Hello Escapists,
I'm learning C++ at the moment and writing a basic program to get into the syntax. However, I can't seem to get my method definitions and declarations right, and at this point, I'm getting "was not declared in this scope" errors. Would anyone mind telling me what I'm missing here?
The code:
Program1Math.h
#ifndef PROGRAM1MATH_H_
#define PROGRAM1MATH_H_
#include
#include <math.h>
using namespace std;
class Program1Math {
void calculateSine(int a);
void calculateTangent(int a);
void calculateModulus(int a, int b);
};
#endif /* PROGRAM1MATH_H_ */
Program1Math.cpp
#include "Program1Math.h"
#include
#include <math.h>
using namespace std;
void calculateSine(int a){
cout<<"Sine("<<a<<") ="<<sin(a);
}
void calculateTangent(int a){
cout<<"Tan("<<a<<") ="<<tan(a);
}
void calculateModulus(int a, int b){
if (a%b==0){
cout<<"/n"<<a<<" is a multiple of "<<b<<"!";
}
else{
cout<<"\n"<<a<<" is not a multiple of "<<b<<".";
}
}
Program1.cpp
#include "Program1Math.h"
#include
using namespace std;
int main(){
int num1;
int num2;
int i=1;
/*Note: I mean this to loop infinitely here.
while (i>0){
cout<<"Please enter the first integer number:\n";
cin>>num1;
cout<<"\nPlease enter the second integer number:\n";
cin>>num2;
calculateModulus(num1, num2);
calculateSine(num1);
calculateTangent(num1);
calculateSine(num2);
calculateTangent(num2);
cout<<"/n/n";
}
return 0;
}
I'm learning C++ at the moment and writing a basic program to get into the syntax. However, I can't seem to get my method definitions and declarations right, and at this point, I'm getting "was not declared in this scope" errors. Would anyone mind telling me what I'm missing here?
The code:
Program1Math.h
#ifndef PROGRAM1MATH_H_
#define PROGRAM1MATH_H_
#include
#include <math.h>
using namespace std;
class Program1Math {
void calculateSine(int a);
void calculateTangent(int a);
void calculateModulus(int a, int b);
};
#endif /* PROGRAM1MATH_H_ */
Program1Math.cpp
#include "Program1Math.h"
#include
#include <math.h>
using namespace std;
void calculateSine(int a){
cout<<"Sine("<<a<<") ="<<sin(a);
}
void calculateTangent(int a){
cout<<"Tan("<<a<<") ="<<tan(a);
}
void calculateModulus(int a, int b){
if (a%b==0){
cout<<"/n"<<a<<" is a multiple of "<<b<<"!";
}
else{
cout<<"\n"<<a<<" is not a multiple of "<<b<<".";
}
}
Program1.cpp
#include "Program1Math.h"
#include
using namespace std;
int main(){
int num1;
int num2;
int i=1;
/*Note: I mean this to loop infinitely here.
while (i>0){
cout<<"Please enter the first integer number:\n";
cin>>num1;
cout<<"\nPlease enter the second integer number:\n";
cin>>num2;
calculateModulus(num1, num2);
calculateSine(num1);
calculateTangent(num1);
calculateSine(num2);
calculateTangent(num2);
cout<<"/n/n";
}
return 0;
}