Need help with my C++ Program Y/N Input if not Y/N displays Invalid input?

Really need your help.. see bottom part.

include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;

int main(void)
{
int num;
char again('Y');

do
{
system("CLS");
cout << "This program will create a pinwheel using the asterisk symbol." << endl
<< "The size of the pinwheel will depend on the user-inputted value." << endl
<< "************************ Let's Start! ************************\n\n"
<< "Please input a number which is <= 39: ";
cin >> num;


for (int i = 1; i <= num; ++i)
{
for (int j = 1; j <= i; ++j)
cout << '*';
for (int k = 1; k <= num - i ; ++k)
cout << ' ';
for (int l = 1; l <= (num + 1) - i; ++l)
cout << '*';
cout << endl;
}

for (int m = 1; m <= num; ++m)
{
for (int k = 1; k <= num - m ; ++k)
cout << ' ';
for (int j = 1; j <= m; ++j)
cout << '*';
for (int l = 1; l <= m - 1; ++l)
cout << ' ';
for (int n = 1; n <= (num + 1) - m; ++n)
cout << '*';
cout << endl;
}
cout << endl << "Do you want to try again? (Y/N): ";
cin >> again;
} while (!(again == 'N' || again == 'n'));
cout<<"Thanks for trying!!";
return 0;
}

I have problems in my Y/N statement. As I enter other variables rather than Y or N, it still acts as 'Y'. How can I make it to display "Invalid input" then have it ask to enter Y or N only.
Here is a good way of quitting something:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <locale>
char answer;
bool Quit = false;

while (!Quit) {
cout << "Do you want to quit? Y or N";
cin >> answer;
answer = std::toupper(answer);
 
if (answer = 'Y')
   Quit = true;

}


In future please always use code tags - the <> button on the right. And always post the compiler output in full, if you have any.

Also the standard idiom for doing some n times is:

1
2
3
4
for (int Count = 0; Count < n ; Count++) {

//your code here
}


Hope all goes well.
Topic archived. No new replies allowed.