total, sum program
Sep 21, 2016 at 12:13pm UTC
I have basically just started learning c++ and I am trying to create a program that allows the user to enter numbers and everytime a total will be give, however,I seem to be having a problem with it looping, any help would be appreciated. thanks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <iostream>
using namespace std;
int main()
{
float num;
float total;
total = 0;
do {
cout << "Enter a number" << endl;
cin >> num;
total = total + num;
cout << total << endl;
} while (num = 00);
system("pause" );
return 0;
}
Sep 21, 2016 at 12:18pm UTC
} while (num = 00);
Should be :
} while (num == 00 );
When you compare a value to a value, use the equality comparison operator (==) not assignment operator (=).
Sep 21, 2016 at 12:26pm UTC
I changed it to == but still not looping
Sep 21, 2016 at 12:33pm UTC
Well,
} while (num != 00 );
When you enter '0', the loop will terminate.
Sep 21, 2016 at 12:49pm UTC
omg of course. foolish mistake. thanks for pointing it out
Topic archived. No new replies allowed.