do while loop

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.

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
#include <iostream>
using namespace 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;

}
Does this even compile?

OK, yes it does - I was expecting a warning at least from the missing return outside of that final if.
Last edited on
First, a couple of points ...

 
if (a, b, c, d = 0)


The above code is performing four checks:

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.

Cheers,
Jim
Topic archived. No new replies allowed.