Randomize

Pages: 12
Your switch statement is not quite correct. You dont need 4 different chars, just one.

1
2
3
4
5
6
if (x == 1)
	{
		quest1 = "\nIf the dog died last night. Did the dog died?";
		cout<<"\na. Yes					b. The dog is immortal";
		cout<<"\nc. No					d. Just soccery";
	}


If you randomly get that question. Im assuming the answer is a. then you just want to create a char and name it answer or something - char answer; instead of char a,b,c,d; Then just put answer in the switch statement, and if the user enters 'a' they will get "correct!, if they enter b c or d, they will get 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
char answer;
	cout << "\n\n\n\n\nQuestion no.1" << quest1;
	cout << "Enter your choice: ";
	cin >> answer;

	switch (answer)
	{
	case 1:
		
		case 'a':
		
			cout << "Correct!";
			break;
		case 'b':
		
			cout << "Wrong!";
			break;
		case 'c':
		
			cout << "Wrong!";
			break;
		case 'd':
		
			cout << "Wrong!";
			break;
		}


Edit: Thing is, this switch statement only applies to the first question. Since your question is randomly chosen, and the answer to all 3 of them is probably not "a" then this wont work.
Last edited on
Im studying in state university sir. But im not an IT or ComSci sir. Our programming subject is just a minor subject.

Thanks so much sir. I think I need to figure this out.
Honestly just watch these tutorials https://www.youtube.com/playlist?list=PLAE85DE8440AA6B83
Like Ive told you before I think. The guy has them on pretty much everything you need, look up the one with switch statements so you can learn how they work and so on and so forth.
Thanks sir. Gonna watch his video :) And thanks sir because it's okay now :)
Topic archived. No new replies allowed.
Pages: 12