C++ 错误 C2059

标签 c++ compiler-errors

已解决


当我尝试编译这个程序时,我不断收到这些错误:

(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/

相关文章:

c++ - typeid 导致不同的编译器

c++ - 我如何使用汇编程序从英特尔处理器中获取随机数?

c++ - 来自 testdome 的二叉搜索树

c# - 关于声明泛型嵌套类的编译错误

编译器错误(在 ')' 标记之前应为 ';')并且不在循环内中断

java - 字符.isDigit()错误: no suitable method found for isDigit(String)

Swift 4 - 表达式太复杂,无法在合理的时间内解决

c++ - Bison 上下文中使用的 C++ 中的 union

c++ - char * 投入 cout 时得到垃圾

java - If 语句中的二维数组