Simple IF Question

I am writing a simple math quiz which involves random numbers. After the user has finished the quiz, they are asked to retry the quiz. To try again, they must type 'yes'. However, when I do the following, no matter what I type the code starts again? Even if I write something like potato it starts again? Thanks

1
2
3
4
5
6
7
8
9
  string retry;
  if (retry == "Yes" or "yes" or "y"){
repeat the code
}

else{
do nothing
}
Also, I am using the program 'CodeBlocks', if that makes any difference.
You should take in the values regarding the retry through the iostream...

Because the string "retry" is not initialized with a value.

Maybe a bit more like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

int main() {
//...

  char retry;

  std::cout << "If you want to restart the program, please type 'Y'."\n";

  std::cin >> retry;

  if (retry == "y" | "Y") { 

    //repeat the code..

  } //if

  //...

} //int main 


Sorry if this is a bit confusing.

What I am trying to tell you is, that you should use the iostream to "catch" the results ;)

Cheers
Last edited on
@MokkaTech
Thanks, did the trick.
Awesome
Topic archived. No new replies allowed.