c++ code problems

I'm trying to create a program that calculates net from gross pay - taxes...however after I enter my gross pay the program closes out...can anyone help me figure out what is wrong with my code?




#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
double inputGross = 0.0;
double FED_RATE = .2;
double STATE_RATE = .05;
//assign the int data type to each variable
int gross = 0;
double federalTax = 0;
double stateTax = 0;
int net = 0;

cout << "Gross pay: ";
cin >> inputGross;

//multiply inputGross by 100, assigning the result (as an integer) to gross
gross = inputGross * 100;
//multiply gross by FED_RATE, then add .5; assign the result (as an integer) to federalTax
federalTax = gross * FED_RATE + .5;
//multiply gross by STATE_RATE, then add .5; assign the result (as an integer) to stateTax
stateTax = gross * STATE_RATE + .5;
net = gross - federalTax - stateTax;

//display the gross, federalTax, stateTax, and net
//divide each value by 100.0 before displaying
gross /= 100.0;
federalTax /= 100.0;
stateTax /= 100.0;

cout << fixed << setprecision(2) << endl;
cout << "Gross: " << gross << endl;
cout << "Federal:-" << federalTax << endl;
cout << "State: -" << stateTax << endl;
cout << " -----" << endl;
cout << "Net: " << net << endl;

return 0;
} //end of main function
closed account (3TkL1hU5)
What IDE are you using?

Try adding #include <limits>

and use this code right before return 0;

1
2
  std::cout << "Press ENTER to continue...";
  std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );


http://www.cplusplus.com/forum/beginner/1988/
No that did not work

I am using Microsoft Visual 2010 Express
closed account (3TkL1hU5)
Are you using F5 to run your program?

Try ctrl + F5.

Last edited on
Topic archived. No new replies allowed.