Why it doesn't loop?

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
#include <iostream>
 #include <cstring>
 #include <cstdio>
 #include <cstdlib>

 using namespace std;

 int main()
 {
 char input[1];
 int x = rand() & 25;
 int y = rand() & 25;
 int a = x+y;
 int answer;
 cout<<"This program is a simple test. You must add 2 random numbers.\n\n";
 do {
 cout<<"The question is: " << x << "+" << y << "= ";
 cin>>answer;
 cout<<"\n\n";
 if (answer == a){
 cout<<"Correct!\n\n";
 cout<<"Would you like to try a new problem? (y/n): ";
 gets(input);
 }
 else if (answer != a) {
 cout<<"Incorrect!\n\n";
 cout<<"Would you like to try again? (y/n): ";
 gets(input);
 }
 } while (strcmp (input, "y") == 0);
 cout<<"Okay.";
 cin.get();
 }



THanks
Well first you can stop using gets and continue to use cin to get input
cin >> input;
Then you can change input to be a single char instead of an array of a single char.......
Then you can just compare input directly to the character 'y' instead of using strcmp
input == 'y'

btw rand() will continue to return the exact same values because you're never seeding it
Topic archived. No new replies allowed.