i'm working on this lab..
*********
- Write a C++ program consisting of main plus two other functions which will do the following:
- Take an integer input from the keyboard.
- Send the integer to a function which will output the integer to the screen.
- Send the integer to a second function which will tell the user that the integer is an odd value.
- Do not tell the user anything if the integer is an even value.
- Repeat this process until the user enters something which is not an integer; use input validation to check for validity.
- Any not valid input should terminate the program.
*************************
i got almost everything down. Im ready to set up the loop that would repeat this process until the user enters something that isnt an integer, but i'm having a hard time finding a way to validate whether the user input is an integer or not...
any ideas?
Thanks in advance!
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 34 35 36 37 38 39 40 41 42 43 44 45 46
|
#include <iostream>
using namespace std;
void first(int);
void second(int);
int remainder;
int integer;
bool gotValidInput = false;
int main()
{
do
{
cout << "Please enter an integer" << endl;
cin >> integer;
cout << endl;
first(integer);
second(integer);
} while
}
//definition of function first
//this function will output integer into the screen
void first(int integer)
{
cout << "you entered the integer: " << integer << endl ;
}
//definition of function second
void second(int integer)
{
remainder = integer % 2;
if (remainder != 0)
cout << endl << "the integer you entered is an odd value" << endl;
else
cout << endl;
}
|