Problem with decimals

So I am supposed to write a program that asks the user to input their income and then display their income. I was supposed to create function called getIncome to ask for the user to input their income. I did that. I just can't figure out how to get the decimals to show. For example if I type in 932.16 as my income it shows up as 932.00

What am I doing wrong?

#include <iostream>
#include <iomanip>
using namspace std;

int getIncome()

{

int income
cout << "\t Your monthly income: ";
cin >> income;

return income;
}

int main()
{

cout.setf(ios::fixed);
cout.setf(ios::showpoint);

int income = getIncome();

cout << "Your income is: $" << setprecision (2) << setw(9) << income;

return 0;

}


Last edited on
ints can't store floating point values so you have to use float instead.
Also you misspelled namespace and you forgot to put a semicolon in function getIncome.
Yeah sorry for the little errors its right in the terminal itself I just didn't know how to copy and paste out of emacs. Anyway thank you very much that fixed the problem right there!
Topic archived. No new replies allowed.