trying to get multiple inputs, program closes after one

Hello. I am a complete noob when it comes to C++. This is a homework question. Feel free to either tell me exactly what I am doing wrong, or give me a hint. I have tried everything I can think of though, and I have no idea where this is going wrong. Basically one of my assignments is to write a program where you can input the month and total money collected. I'm then supposed to display a table where those values entered are then broken down into various categories.

My problem is after I enter a month, the program closes. I cannot get it to remain open past that stage and cannot progress any further. Thank you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  // This program calculates monthly sales tax
#include <iostream>
using namespace std;

int main()
{

	int month, total;

	cout << "What month are you calculating? ";
	cin >> month;
	cin.ignore();
	cout << "What is the amount of money collected for this month? ";
	cin >> total;
	cin.ignore();

	cout << "Month: " << month << endl;

	cout << "Total Collected: " << total << endl;
	cout << "Sales: " << (total / 1.06);
	cout << "County Sales Tax: " << (total / 0.02);
	cout << "State Sales Tax: " << (total / 0.04);
	cout << "Total Sales Tax: " << (total / 0.06);
	return 0;


}
closed account (E0p9LyTq)
Look here:

Console Closing Down
http://www.cplusplus.com/forum/beginner/1988/

Yes, it is a lot to go through, but worth the read.
I've read through all seven pages, even tried some of the recommendations, my program still shuts down after my first input.
Please provide a sample input that exhibits this problem, and the program's output (if any).

Note that you must enter strings that look like a valid int: you can't enter "January", for example, when prompted for the month. Entering something invalid will indeed cause the behavior you're describing.

Why are you ignoring parts of your input? (You don't need to do this, although it doesn't make any difference here.)
Last edited on
Topic archived. No new replies allowed.