Solved
When I try to compile this program i keep getting these 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;
};
This is part of a homework a开发者_开发问答ssignment so any pointers on bettering my programing would be **great**
Note:I am using Windows 7 with VS express C++ 2008
income
is the name of your class. _incm
is the name of your variable. Perhaps you meant this (notice the use of _incm
not 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. Since C++ is case-sensitive, they wouldn't conflict each other if they use different case.
Your variable is named incom
, not 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.
One note for bettering you programming would be to use more distinct variable names to avoid such confusions... ;)
精彩评论