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?
#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!