My do while loop isn't looping!

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <ctime>
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
 {

	int num  = 0;
	int num2 = 0;
	int num3 = 0;
	int num4 = 0;
	int user = 0;
	char user2= 0;
	int answer1 = 0;
	float count = 0;
	float percent;
	
	
	srand(unsigned(time(0)));
do
{
while(user2=='y' || user2=='Y');
	{
			for(int i=1 ; i<=5 ; i++)
				{		
					num = (rand()%8)+ 2;
						num2= (rand()%8)+ 2;
							num3=num;
								num4=num2;
							answer1=num*num2;	
					
					

				while(num==num4 && num2==num3 && num==num3 && num2==num4)
						{	
							num= (rand()%8)+ 2;
							num2= (rand()%8)+ 2;
							answer1=num*num2;
						}			
						
				
				
cout<<"\nWhat is "<<num<<" x "<<num2<<endl;
cin>>user;

	

						if(answer1==user)
							{	
								cout<<"Right!\n";
								count++;
							}
						if(answer1!=user)
							cout<<"\nWrong! -> "<<num<<" x "<<num2<<" = "<<answer1;

			}	

	}

}while(user2=='n' || user2=='N');	

	percent=(count / 5)*100;
	cout<<"\nYou got "<<count<<" out "<<"5 right, which is "<< percent <<"%\n\n";
	cout<<"\nPlay again [y/n]:";
	cin>>user2;
					

	
				
			if(percent<=25)
				{	
			cout<<endl;	
					for(int a=1;a<=9;a++)
						cout<<a<<' ';
					
			cout<<endl;	
					for(int b=2;b<=18;b++)
							if(b%2==0)
							cout<<b<<' ';

			cout<<endl;
					for(int c=3;c<=27;c++)
						if(c%3==0)
							cout<<c<<' ';
			cout<<endl;
					for(int d=4;d<=36;d++)
						if(d%4==0)
							cout<<d<<' ';
			cout<<endl;
					for(int e=5;e<=45;e++)
						if(e%5==0)
							cout<<e<<' ';
			cout<<endl;
					for(int a2=6;a2<=54;a2++)
						if(a2%6==0)
							cout<<a2<<' ';
			cout<<endl;
					for(int b2=7;b2<=63;b2++)
						if(b2%7==0)
							cout<<b2<<' ';
			cout<<endl;
						
						for(int c2=8;c2<=72;c2++)
						if(c2%8==0)
							cout<<c2<<' ';
			cout<<endl;
						for(int d2=9;d2<=81;d2++)
						if(d2%9==0)
							cout<<d2<<' ';
			cout<<endl;
			
				}


					
					
	system("pause");
	return 0;
}




please help my do while loop isnt working. any help
What is the value of user2 when your program tries to enter the loop?
before the second loop you should give a value to the user2 param.
what you mean i gave the user2 a value of 0 before the loop and i ask the user if he wants to play again if he enters y or Y it re-enters the loop again those 5 rand generated problems.. if enter n or N it exits the program.
I might be really tired but the do-while loops does not look right..

it is:
do
{
do.stuff.in.here
}while(answer != 3)

The end part of the code is not even in a loop. You ask the person if he/she want to go again, and that's that. There is no loop there.

do
{
question
}while(answer != 'n')

Can be wrong, reeaall tired ^^
heymrjack10 wrote:
i gave the user2 a value of 0 before the loop

If user2 has the value 0 before the loop then it won't be equal to 'y' or 'Y' will it? Therefore it will never enter the loop.
Last edited on
Topic archived. No new replies allowed.