problem with code

Hey guys, I had everything right with this code until I added the "do-while" to it. I can't figure out what I'm doing wrong.

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
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <conio.h>
#include <iostream>
#include <iomanip>

using namespace std;

int main() 
{
	const int number = 100;
	char yes;
	int numbers[number];	
	int n, m = 0, o = 1000, p, q, num; /* m is  lowest value in array
							     o is highest value in array */
	srand( (unsigned)time( NULL ) );
	
	do	  
	
	{
	
	for (n = 0; n < 100; n++)
	{

		num = rand()% 1000 + 1;
		numbers[n] = num;
		
		if (m <= num)
		{	 m = num;	 
			 p = n;
		}
			
		if (o >= num)
		{	 o = num;
			 q = n;
		}
	}
	
	
	
	for (n = 0; n < 100; n++)
	{
		cout << "Index # " << n << "\t" << numbers[n] << "\n\n";
	}
	
	cout << m << " is the  lowest value in the array.\n";
	cout << "It is located at array position numbers[" << p << "]\n\n";
	
	
	cout << o << " is the highest value in the array \n";
	cout << "It is located at array position numbers[" << q << "]";
	
	
	cout << "\n\nWanna run this program again?/n";
	cout << "Press Y or y";
	cin >> yes;
	
	}	 while (yes == 'Y') || (yes == 'y');
	
	
	return 0;

}	
Ok I figured out what I was doing wrong. It was the paranthesis before and after the ||.

My problem now since I fixed that is that the code doesn't want to run again after I type the Y or y. Can someone help with that ?
I fixed it, here's what I did.

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <conio.h>
#include <iostream>
#include <iomanip>

using namespace std;

int main() 
{
	const int number = 100;
	char yes, y, Y;
	int numbers[number];	
	int n, m = 0, o = 1000, p, q, num; /* m is  lowest value in array
							     o is highest value in array */
	srand( (unsigned)time( NULL ) );
	
	yes = 'Y';
	
	while (yes == 'Y' || yes == 'y')  
	
	{
	
	for (n = 0; n < 100; n++)
	{

		num = rand()% 1000 + 1;
		numbers[n] = num;
		
		if (m <= num)
		{	 m = num;	 
			 p = n;
		}
			
		if (o >= num)
		{	 o = num;
			 q = n;
		}
	}
	
	
	
	for (n = 0; n < 100; n++)
	{
		cout << "Index # " << n << "\t" << numbers[n] << "\n\n";
	}
	
	cout << m << " is the  lowest value in the array.\n";
	cout << "It is located at array position [" << p << "]\n\n";
	
	
	cout << o << " is the highest value in the array \n";
	cout << "It is located at array position [" << q << "]";
	
	
	cout << "\n\nWanna run this program again?\n";
	cout << "Press Y or y : ";
	cin >> yes;
	
	}	 
	

	
	return 0;

}	


1
2
3
4
5
6
7
8
9

/* ....... */

do
{
           //your code in here 
} while (yes == 'Y' || yes == 'y');

return 0;



Use do-while loop instead
Topic archived. No new replies allowed.