So i want to make sure the input is only a int and it is not trailed by a character. I am up to functions in my intro class so no even moderately advanced stuff.
int main()
{
do
{
cout << "Enter first whole number: "; // asks user for the first input
cin >> num1; cin.ignore(80, '\n'); cin.clear();
isNUM(num1); //calls the function
outputFile << "First number " << num1 << endl; // Saves first number to file GCD.txt
cout << "Enter second whole number: "; // asks user for the second input
cin >> num2; cin.ignore(80, '\n');
isNUM(num2); //calls the function
outputFile << "Second number " << num2 << endl; // Saves second number to file GCD.txt
isGCD(num1, num2); cout << endl; // preforms GCD function and provides solution.
outputFile << "GCD = " << num1 << "\n\n"; // Displays the GDC of the two user number values
cout << "Would you like to calculate again?\nEnter Y for Yes and N for No. "; //asks user if would like to try again
cin >> choice; cin.ignore(80, '\n');// user inputs yes or no
YesOrNo = isTRUE(choice); // takes user character input and either exits or asks again
} while (YesOrNo); // Ends loop in user input is = No
outputFile.close();
cout << "Thank you for using my program.\n\n"; // Says thank you.
system("pause");
return 0;
}
int isNUM(int number)
{
if (number >= 0 || number <= 0 )
{
return number;
}
else
{
while (number == (char)number) //
{
cout << "Bad input try again: ";
cin.clear(number);
cin >> number;