Name: Anonymous 2011-08-31 21:02
Hi
I'm trying to write a payroll program in C++. I used DevC as my compiler, but it's not the best, I know (Windows user). Gcc, MS Visual, and Geany don't do shit for me. So here's my code.
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char *argv[])
{
//declaring variables
double hoursWorked;
double payRate;
double regularPay = hoursWorked * payRate;
double overtimePay = 1.5 * payRate * hoursWorked;
double grossPay = regularPay + overtimePay;
double stateTax;
double federalTax;
double totalTax = federalTax + stateTax;
double unionDues;
double netPay = grossPay - (totalTax + unionDues);
char input;
cout << "Enter total hours \n" << endl;
cin >> hoursWorked;
cout << "Enter rate of pay \n" << endl;
cin >> payRate;
if ( hoursWorked > 40 )
cout << "Gross pay = " << grossPay << 1.5 * payRate * hoursWorked;
else if( hoursWorked <=40 )
cout << "\n\nGross pay = " << grossPay << hoursWorked * payRate;
//state tax section
cout << "\n\nState taxation section \n" << endl;
cout << "Please enter gross pay \n" << endl;
cin >> grossPay;
if ( grossPay < 500 )//use if else statements
cout << "State Tax is 0 \n" << endl;
else
if ( grossPay >= 500 && grossPay < 1000 )
cout << "State Tax is = " << grossPay * ( 3 / 100 ) << endl;
else
if ( grossPay >= 1000 )
cout << "State Tax is = " << grossPay * ( 5 / 100 ) << endl;
system("PAUSE");
return 0;
}
Everything runs fine until the taxation area. Right now the double ampersand is a syntax error, but I had it bracketed out to pass the compiler (per the book I'm reading) and it doesn't recognize that my whole taxation area is one large statement of if/else. It correctly says the tax is 0 for values less than 500, but at 501+ it doesn't say anything. I also tried the traditional way here:
//state tax section
cout << "State Taxation Section. Please Enter Gross Pay. \n" << endl;
if ( grossPay < 500 )//use if else statements
cout << stateTax = 0;
else
if ( grossPay >= 500 )
{ if ( grossPay < 1000 )
cout << stateTax = grossPay * ( 3 / 100 );
}
else
if ( grossPay >= 1000 )
cout << stateTax = grossPay * ( 5 / 100 );
Same issue. Wtf???
I'm trying to write a payroll program in C++. I used DevC as my compiler, but it's not the best, I know (Windows user). Gcc, MS Visual, and Geany don't do shit for me. So here's my code.
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char *argv[])
{
//declaring variables
double hoursWorked;
double payRate;
double regularPay = hoursWorked * payRate;
double overtimePay = 1.5 * payRate * hoursWorked;
double grossPay = regularPay + overtimePay;
double stateTax;
double federalTax;
double totalTax = federalTax + stateTax;
double unionDues;
double netPay = grossPay - (totalTax + unionDues);
char input;
cout << "Enter total hours \n" << endl;
cin >> hoursWorked;
cout << "Enter rate of pay \n" << endl;
cin >> payRate;
if ( hoursWorked > 40 )
cout << "Gross pay = " << grossPay << 1.5 * payRate * hoursWorked;
else if( hoursWorked <=40 )
cout << "\n\nGross pay = " << grossPay << hoursWorked * payRate;
//state tax section
cout << "\n\nState taxation section \n" << endl;
cout << "Please enter gross pay \n" << endl;
cin >> grossPay;
if ( grossPay < 500 )//use if else statements
cout << "State Tax is 0 \n" << endl;
else
if ( grossPay >= 500 && grossPay < 1000 )
cout << "State Tax is = " << grossPay * ( 3 / 100 ) << endl;
else
if ( grossPay >= 1000 )
cout << "State Tax is = " << grossPay * ( 5 / 100 ) << endl;
system("PAUSE");
return 0;
}
Everything runs fine until the taxation area. Right now the double ampersand is a syntax error, but I had it bracketed out to pass the compiler (per the book I'm reading) and it doesn't recognize that my whole taxation area is one large statement of if/else. It correctly says the tax is 0 for values less than 500, but at 501+ it doesn't say anything. I also tried the traditional way here:
//state tax section
cout << "State Taxation Section. Please Enter Gross Pay. \n" << endl;
if ( grossPay < 500 )//use if else statements
cout << stateTax = 0;
else
if ( grossPay >= 500 )
{ if ( grossPay < 1000 )
cout << stateTax = grossPay * ( 3 / 100 );
}
else
if ( grossPay >= 1000 )
cout << stateTax = grossPay * ( 5 / 100 );
Same issue. Wtf???