omit even numbers. please help!

How do I get it to make me enter another number if it isn't an odd number?

#include <cstdlib>
#include <iostream>
using namespace std ;

int main ( )
{
int N ;
char goAgain;

do
{
do
{
cout << endl << "Please enter an odd integer, 1 - 51 : " ;
cin >> N ;
}
while ( N >=51 );

cout << endl ;

cout << "Go again (y for yes, n for no): " ;
cin >> goAgain ;
}
while ( (goAgain == 'y') || (goAgain == 'Y') );
return N ;
}
1
2
3
4
5
6
while( N % 2 == 0 ) //even
{
    cout << "That is an even number" << endl;
    cout << "Please enter an odd number: ";
    cin >> N;
}
I need it with just odd numbers and it has to be between 1 - 51
That's the whole point it looks when it is even. Because you wanted odd for input. You already have the 1 -51 error check also but anyways it would look something like

1
2
3
4
5
6
7
do
{
    cout << "Please enter an odd integer( 1 - 51 ): ";
    cin >> N;
    if( N < 1 || N > 51 || N % 2 == 0 ) //less than 1 , more than 51 or even
        cout << "Invalid number." << endl;
} while( N < 1 || N > 51 || N % 2 == 0 ); //less than 1 greater than 51 or even 
Topic archived. No new replies allowed.