Input

This is going to be a very easy fix most likely, but I have been trying to program a simple program that asks for a monthly budget, the user then puts it in, then it outputs Your monthly budget with the number the user put in. I have coded half of the problem, but I keep getting your monthly income is and it doesn't display the number that I put it in earlier. I have looked everywhere and can't find my mistake, below is my code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream> 
#include <iomanip>

int main ()
{ //declares the variable
 float monthlyIncome;

//asks the user what their monthly income is 
cout <<"\t"
     << "Your monthly income: ";
cin >> monthlyIncome

//configures the display to show monthly budget within 2 decimal places
cout.setf(ios::fixed); 
cout.setf(ios::showpoint);
cout.precision(2);

//display the results 
cout << "Your income is: " 
     << setw(9) << "$" monthlyIncome; 
     return 0; 
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <iomanip>

using namespace std; //added

int main()
{ //declares the variable
	float monthlyIncome;

	//asks the user what their monthly income is 
	cout << "\t" << "Your monthly income: ";
	cin >> monthlyIncome;

	//configures the display to show monthly budget within 2 decimal places
	cout << fixed << setprecision(2);

	//display the results 
	cout << "Your income is: "<< setw(9) << "$" << monthlyIncome;
	return 0;
}
Last edited on
Thanks so much! I can't believe I forgot the namespace, I just have some formatting issues to fix, but at least it's computing the number now.
Topic archived. No new replies allowed.