1
    correct = 0;
    cout << "You entered " << years << ".\nIs that correct? (Y/N) \n";
    cin >> yesNo;
    if (yesNo == 'y' || 'Y')
         correct ++;
} while (correct != 1);
    cout << "good! " << correct << endl;
return 0;

} I want it to only ++ the correct int if yesNo = y or Y, if it doesn't, I want it to loop back up to the top (unseen)

  • Try not to guess the syntax, you can and will get results you won't expect. Like `'Y'` evaluating to `true`, so you're whole condition is always true? You might want to read a [good book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – Rakete1111 Nov 11 '17 at 21:48
  • 1
    You should turn on your compiler warnings, i'm sure it'll cringe at `(yesNo == 'y' || 'Y')`. – George Nov 11 '17 at 21:48
  • While you're at it. Make `correct` a `bool`. – Hatted Rooster Nov 11 '17 at 21:49
  • I changed correct to bool, and I also changed the if statement to include yesNo on both parts of or. – Zheis Viscia Nov 11 '17 at 21:59
  • Also I'm going to check out one of those books at least. Right now I'm using fundamentals of c++ by Tony Gaddis. Can I upvote comments? RickAstley helped out and I wanted to give him some rep or something positive. – Zheis Viscia Nov 11 '17 at 22:01

2 Answers2

6

I guess your problem is in

if (yesNo == 'y' || 'Y')

It should be

if (yesNo == 'y' || yesNo== 'Y')
CodeZero
  • 1,649
  • 11
  • 18
3

http://coliru.stacked-crooked.com/a/5bf3edba51feec45

Your problem is the if (yesNo == 'y' || 'Y'). What this if-statement says, is

If yesNo is equal to 'y' or 'Y' is true, proceed.

The thing is, 'Y' is always true, because the char is implicitly converted into a bool.

What you probably meant, is if (yesNo == 'y' || yesNo == 'Y')

Post Self
  • 1,471
  • 2
  • 14
  • 34
  • 1
    Thanks for your answer. I used the above answer, but I just wanted to let you know that I appreciate the information you gave in addition to the answer. – Zheis Viscia Nov 11 '17 at 22:12