简体   繁体   English

C ++错误C2059

[英]C++ error C2059

Solved 解决了


When I try to compile this program i keep getting these errors: 当我尝试编译该程序时,我不断遇到这些错误:

(50) : error C2059: syntax error : '<=' (50):错误C2059:语法错误:'<='

(50) : error C2143: syntax error : missing ';' (50):错误C2143:语法错误:缺少';' before '{' 在“ {”之前

(51) : error C2059: syntax error : '>' (51):错误C2059:语法错误:'>'

(51) : error C2143: syntax error : missing ';' (51):错误C2143:语法错误:缺少';' before '{' 在“ {”之前

(62) : error C2059: syntax error : 'else' (62):错误C2059:语法错误:“ else”

(62) : error C2143: syntax error : missing ';' (62):错误C2143:语法错误:缺少';' 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;
};

This is part of a homework assignment so any pointers on bettering my programing would be **great** 这是家庭作业的一部分,因此,任何有关改善我的编程的建议都是“很棒的”

Note:I am using Windows 7 with VS express C++ 2008 注意:我将Windows 7与VS Express C ++ 2008一起使用

Your variable is named incom , not income . 您的变量名为incom ,而不是income income refers to a type, so the compiler gets confused and you get a syntax error when you try to compare that type against a value in line 50. income是指一种类型,因此当您尝试将该类型与第50行中的值进行比较时,编译器会感到困惑,并且会遇到语法错误。

One note for bettering you programming would be to use more distinct variable names to avoid such confusions... ;) 改善编程的一个注意事项是使用更多不同的变量名,以避免此类混淆...;)

income is the name of your class. income是你班级的名字。 _incm is the name of your variable. _incm是变量的名称。 Perhaps you meant this (notice the use of _incm not income ): 也许您的意思是这样(注意使用_incm而不是income ):

if (_incm <= 0) { cout << "the income must be greater than 0... \n" << endl; }
if (_incm > 0) { done = true; _new.setIncm(_incm); }

Frequently you use CamelCase for class names and lowercase for instance variable names. 通常,将CamelCase用于类名,将小写用于实例变量名。 Since C++ is case-sensitive, they wouldn't conflict each other if they use different case. 由于C ++区分大小写,因此如果使用不同的大小写,它们不会互相冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM