• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

C++ n00b please help!

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Krack3d

Registered
Joined
Jul 24, 2004
Alright I'm making a program to calculate a paycheck heres what I have:


#include <iostream>
using namespace std;
int main()
{

//Declares the different variables used
double Gross_Pay; //Gross Pay
double FIT; //Federal Income Tax
double SIT; //State Income Tax
double SST; //Social Security Tax
double Union_Dues; //Union Dues
double Hours_Worked; //Hours Worked
double Pay_Rate; //Pay Rate
double Net_Pay; //Net Pay
double Health; //Health Tax
double Health_Cov; //Health Coverage
char f, F, s, S;

//Program introduction
cout << "Hello. Welcome to the paycheck calculator." << endl;

cout << "Enter your pay rate:"; //Intakes the users pay rate
cin >> Pay_Rate;

cout << "Enter the number of hours you worked:"; //Intakes number
cin >> Hours_Worked; //of hours worked

cout << "Enter s for single or f for family health coverage:";
cin >> Health_Cov; //Intakes health coverage as family or si\
ngle

//Equations to determine final results

Gross_Pay = Hours_Worked * Pay_Rate; //Calculates Gross Pay

FIT = Gross_Pay * .14; //Calculates the Federal Income Tax

SIT = Gross_Pay * .05; //Calculates the State Income Tax

SST = Gross_Pay *.06; //Calculates the Social Security Tax

if (Hours_Worked >= 35)
Union_Dues = 10;
else
Union_Dues=0;

if ((Health_Cov == f) || (Health_Cov == F))
Health = 35;
else ((Health_Cov == s) || (Health_Cov == S)
Health = 0;
if ((Health_Cov != s)&& (Health_Cov != S) && (Health_Cov != f) && (Health_Cov\
!= F))
Health = "Error";

cout << "Your pay rate: " << Pay_Rate << endl;
cout << "Hours Worked: " << Hours_Worked << endl;
cout << "Gross Pay: " << Gross_Pay << endl;
cout << "Federal Tax: " << FIT << endl;
cout << "State Tax: " << SIT << endl;
cout << "Social Security Tax: " << SST << endl;
cout << "Union Dues: " << Union_Dues << endl;
cout << "Health: " << Health << endl;
cout << "---------------------------" << endl;
cout << "Net Pay:" << Gross_Pay << endl;

return 0;
}





Heres the error messages I get:

Stopped (user)
unix2% g++ hw2.cpp -o hw2
hw2.cpp: In function `int main()':
hw2.cpp:61: parse error before `='
hw2.cpp:62: parse error before `)'
hw2.cpp:77: confused by earlier errors, bailing out
unix2%


I'm a complete C++ newbie and this is due in like 3 hours so please help Im lost
 
Code:
 if ((Health_Cov != s)&& (Health_Cov != S) && (Health_Cov != f) && (Health_Cov[I][B][SIZE=4][COLOR=DarkRed]\[/COLOR][/SIZE][/B][/I]!= F))

Should that \ be there?
 
No.. that appeared during copying and pasting.. I changed the program a bit and tried to make it loop but Im still getting error messages not so many this time though here it is:


#include <iostream>
using namespace std;
int main()
{

//Declares the different variables used
double Gross_Pay; //Gross Pay
double FIT; //Federal Income Tax
double SIT; //State Income Tax
double SST; //Social Security Tax
double Union_Dues; //Union Dues
double Hours_Worked; //Hours Worked
double Pay_Rate; //Pay Rate
double Net_Pay; //Net Pay
char Health; //Health Tax
char Health_Cov; //Health Coverage
char ans; //yes or no to restart
char Error;

do
{
//Program introduction
cout << "Hello. Welcome to the paycheck calculator." << endl;

cout << "Enter your pay rate: "; //Intakes the users pay rate
cin >> Pay_Rate;

cout << "Enter the number of hours you worked: "; //Intakes number
cin >> Hours_Worked; //of hours worked
cout << "Enter s for single or f for family health coverage: ";
cin >> Health_Cov; //Intakes health coverage as family or single

//Equations to determine final results

Gross_Pay = Hours_Worked * Pay_Rate; //Calculates Gross Pay

FIT = Gross_Pay * .14; //Calculates the Federal Income Tax

SIT = Gross_Pay * .05; //Calculates the State Income Tax

SST = Gross_Pay *.06; //Calculates the Social Security Tax

if (Hours_Worked >= 35)
Union_Dues = 10;
else
Union_Dues = 0;

if (Health_Cov == 'f' || Health_Cov == 'F')
Health = 35;
else
Health = 0;
if (Health_Cov != 's' || Health_Cov != 'S' || Health_Cov != 'f' || Health_Cov != 'F')
Health = Error;

cout << "Your pay rate: " << Pay_Rate << endl;
cout << "Hours Worked: " << Hours_Worked << endl;
cout << "Gross Pay: " << Gross_Pay << endl;
cout << "Federal Tax: " << FIT << endl;
cout << "State Tax: " << SIT << endl; //Outputs all the results before asking to repeat
cout << "Social Security Tax: " << SST << endl;
cout << "Union Dues: " << Union_Dues << endl;
if (Health = Error)
cout << "Health: Error/n";
else
cout << "Health: " << Health << endl;
cout << "---------------------------" << endl;
cout << "Net Pay:" << Gross_Pay << endl;
cout << "Would you like to try again? [y/n]: "
cin >> ans;
} while (ans == 'y' || ans == 'Y');
cout << "Goodbye!/n";
return 0;
}






The error I now get is:

Stopped (user)
unix1% g++ hw2.cpp -o hw2
hw2.cpp: In function `int main()':
hw2.cpp:82: parse error before `>'
unix1%



Helppppp!! the parse error is in my last cin statement btw.
 
Well one potential problem is that your types don't match for the health coverage:

char Health; //Health Tax

if (Health_Cov == 'f' || Health_Cov == 'F')
Health = 35;
else
Health = 0;
if (Health_Cov != 's' || Health_Cov != 'S' || Health_Cov != 'f' || Health_Cov != 'F')
Health = Error;

Health is decalred as a char, but you are trying to put an int into that variable. You also declare char Error, but never give it any value, and then assign it to Health in part of that if statement. That shouldn't cause you this error, but will cause run time errors.
 
A lot of times, parse or syntax errors will be reported at some point after where the error actually is. The reasoning is a bit technical. Its a good idea to always look back at the previous opertion or statement. That said, lets look at the statement with the error and the end of the previous one:

cout << "Would you like to try again? [y/n]: "
cin >> ans;

You are missing a ';' at the end of the cout statement.
 
yes I'm a moron but its too late now had to submit it yetsterday x_x
 
Back