I am trying to write a do while loop that asks the user for a series of integers one at a time, and when the integer 0 is entered, it has to display the number of integers in the series excluding zero.
#include <iostream>
usingnamespace std;
int main()
{
int a,b,c,d;
cout << "There are four values, a,b,c.and d."<< endl;
do
{
cout << "What is the value of a?" << endl;
cin >> a;
cout << "What is the value of b?" << endl;
cin >> b;
cout << "What is the value of c?" << endl;
cin >> c;
cout << "What is the value of d?" << endl;
cin >> d;
}
while (a,b, c, d != 0);
if (a,b,c,d = 0 )
return 0;
}
1: That a is non-zero
2: That b is non-zero
3: That c is non-zero
4: That the result of assigning d with the value 0 is non-zero (which it won't be - it'll be zero)
That last one should be d == 0
I suspect you were wanting if (a == 0 || b == 0 || c == 0 || d == 0) which checks whether any of a, b, c or d is zero.
But - you're going about the problem wrong - you need to be reading the numbers into an array until you get a zero, at which point you print out the array contents.