已解决
当我尝试编译这个程序时,我不断收到这些错误:
(50) : error C2059: syntax error : '<='
(50) : error C2143: syntax error : missing ';' before '{'
(51) : error C2059: syntax error : '>'
(51) : error C2143: syntax error : missing ';' before '{'
(62) : error C2059: syntax error : 'else'
(62) : error C2143: syntax error : missing ';' before '{'
#include <iostream>
#include <string>
#include <cassert>
using namespace std;
class income {
private:
double incm;
double subtract;
double taxRate;
double add;
char status;
public:
void setStatus ( char stats ) { status = stats; }
void setIncm (double in ) { incm = in; }
void setSubtract ( double sub ) { subtract = sub; }
void setTaxRate ( double rate ) { taxRate = rate; }
void setAdd ( double Add ) { add = Add; }
char getStatus () { return status; }
double getIncm () { return incm; }
double getsubtract () { return subtract; }
double getTaxRate () { return taxRate; }
double getAdd () { return add; }
void calcIncome ();
};
//calcIncome
int main () {
income _new;
double ajIncome = 0, _incm = 0;
char status = ' ';
bool done = false;
while ( !done ) {
cout << "Please enter your TAXABLE INCOME:\n" << endl;
cin >> _incm;
if(cin.fail()) { cin.clear(); }
if ( _incm <= 0) { cout << "the income must be greater than 0... \n" << endl; }
if ( _incm > 0) { done = true; _new.setIncm(_incm); }
}
done = false;
char stt [2] = " ";
while ( !done ) {
cout << "Please declare weather you are filing taxes jointly or single" << "\n";
cout << "\t's' = single\n\t'm' = married" << endl;
cin >> stt;
if(cin.fail()) { cin.clear(); }
if ( status == 's' || status == 'm' ) { done = true; _new.setStatus(stt[0]); }
//if else { }
}
return 0;
};
这是家庭作业的一部分,因此任何关于改进我的编程的指示都将是**好的**
注意:我使用的是 Windows 7 和 VS express C++ 2008
最佳答案
income
是您类(class)的名称。 _incm
是您的变量名。也许你的意思是这个(注意使用 _incm
而不是 income
):
if (_incm <= 0) { cout << "the income must be greater than 0... \n" << endl; }
if (_incm > 0) { done = true; _new.setIncm(_incm); }
您经常使用 CamelCase类名小写,实例变量名小写。由于 C++ 是区分大小写的,因此如果它们使用不同的大小写,它们不会相互冲突。
关于C++ 错误 C2059,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2057950/