Program exits

Program keeps exiting after I enter the value for number of dollars. I am new, and am sure the answer is obvious, but I cannot seem to figure it out. I also am receiving an error stating that visual studio cannot find object files for debugging, and that subsequent failures will be logged to the debug pane.


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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string name;
	int dollar, quarter, dime, nickel, penny;

	


	    dollar = 1
		quarter = 25
		dime = 10
		nickel = 5
		penny = 1


	// input servers name
	cout << "What is your name?";
		getline(cin, name);
	

	//input dollars made
		cout << "how many dollars did you receive";
		cin >> dollar; 
	

	// input quarters made
	cout << "Quarters received?";
	cin >> quarter;

	// input dimes
	cout << "dimes";
	cin >> dime;
	
	// input nickel 
	cout << "nickels?"
		cin >> nickel;

	// input penny
	cout << "pennies";
	cin >> penny;


	system("PAUSE");
	return 0;

}
Last edited on
Hello TheArk,

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.


When you enter for "dollar" exactly what do you type? Do not leave anything out.

Andy
Last edited on
Okay, thanks for notifying me of that I will be sure to do that next time I post, I apologize.

When I enter for "dollar", I have entered numbers such as 1, or 2, and have also entered symbols, or letters, and it still exits after entering.

Hello TheArk,

As I looked over your program I noticed that lines 13 - 17 are missing semi-colons and also line 39.

I was thinking you might have entered "$10" where the "$" would cause cin to fail which would not allow any other entries. Just a thought for now. I load up your program and give it a test.

Be patient, it could be tomorrow morning before I can get back to you.

Hope that helps.

Andy
Handy Andy you are amazing. The problem was the semi colons, I figured it was something in plain sight. You are very much appreciated, as I have been messing with this for about 3 hours now thinking something was wrong with my computer. I am sure I will run into you again on here. Thank you much!
Hello TheArk,

Your welcome.

After fixing the semi-colon problem the program worked fine. I could not break it unless I entered something other than a number.

At some point you might want to consider this or your program:

1
2
3
4
5
6
7
8
9
10
11
12
	//input dollars made
	std::cout << "how many dollars did you receive: ";
	std::cin >> dollar;

	while (!std::cin)
	{
		std::cout << "\n Error message of your choice" << std::endl;
		std::cin.clear();  // <--- Clears the state bits that caused cin to fail.
		std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Add header files "chrono" and "thread".
		std::cin >> dollar;
	}


An easy way to do a check on what was entered.

Hope that helps,

Andy
Last edited on
Topic archived. No new replies allowed.