Continuous stream of sums

Jun 14, 2015 at 12:51pm
I've got this practice problem working nearly 100%, however the program outputs a crazy number after the first two inputs are received(I've seen . Any tips?

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
#include <iostream>
#include <string>

using std::cout;	using std::cin;
using std::endl;

int main()
{
	double x;
	double y;
	double z;
	double answer;

	cout << "Please enter a number, 0 to exit program:" << endl;
	cin >> x;
	if (x == 0)
	{
		return 0;
	}

	cout << "Please enter another number, or 0 to exit: " << endl;
	cin >> y;
	if (y == 0)
	{
		return 0;
	}
	
	cout << x << '+ ' << y << '= ' << x + y << endl; // I believe the  
        //   problem is here, just can't see what the exact issue is.
        // It outputs numbers like 1110401156482.

	answer = x + y;

	cout << "And another number" << endl;
	cin >> z;

	while (z != 0)
	{
		cout << "answer + z = " << answer + z << endl;
		answer += z;

		cout << "And another number, zero exits the program: " << endl;
		cin >> z;

	}

	return 0;
}


I thought I had a decent handle on this but this kind of wall gets slightly
frustrating haha, any help would be awesome!
Jun 14, 2015 at 12:57pm
line 28, you are supposed to use double quotes, not single quotes.
Last edited on Jun 14, 2015 at 12:57pm
Jun 14, 2015 at 1:00pm
thank you very much, I knew that line was the issue! Just needed a more experienced eye to call me out on my syntax. Thanks again!
Topic archived. No new replies allowed.