嘿,你可以請檢查我的代碼在下面? 這只是一個簡單的計算器。 我想問一下這有什麼問題。CodeBlocks C++使用類
我得到錯誤「4號線錯誤:預期不合格-ID之前‘)’標記
#include<iostream>
using namespace std;
class Calculator()
{
public:
int AdditionFunction(float num1, float num2)
{
sum = num1 + num2;
}
int SubtractionFunction(float num1, float num2)
{
diff = num1 - num2;
}
int MultiplicationFunction(float num1, float num2)
{
prod = num1 * num2;
}
int DivisionFunction(float num1, float num2)
{
quo = num1/num2;
}
public:
return sum;
return diff;
return prod;
return quo;
private:
float sum;
float diff;
float prod;
float quo;
};
int main()
{
float num1, float num2;
int choice;
Math MathObj;
cout<<"Enter first number: ";
cin>>num1;
cout<<"Enter second number: ";
cin>>num2;
cout<<"What operation to be used? "<<endl;
cout<<"1.Addition"<<endl;
cout<<"2.Subtraction"<<endl;
cout<<"3.Multiplication"<<endl;
cout<<"4.Division"<<endl;
cout<<"Choose from 1-5"<<endl<<"Enter your choice here: ";
cin>>choice;
if (choice == 1)
{
MathObj.AdditonFunction(0,0);
}
same as for Subtraction and so on. Ends with a return 0;
我寫了我這樣的代碼,因爲我看,這是一個良好的編程習慣把你的變量私人而不是公衆。我將很高興知道答案。
我無法想象你在哪裏看到類似'public:return sum;'的代碼。它看起來像你應該開始[這裏](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)。 – molbdnilo