Last active
December 27, 2015 17:49
-
-
Save martynchamberlin/7364709 to your computer and use it in GitHub Desktop.
Console C++ application. Gets user input and checks to see if it is a valid integer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
bool isInt(char tempNumber); | |
int main() | |
{ | |
char tempNumber[10]; | |
while ( true ) | |
{ | |
cout << "Enter a number: "; | |
cin >> tempNumber; | |
bool isIntMain = true; | |
for ( int i = 0; i < tempNumber[i]; i++ ) | |
if ( ! isInt( tempNumber[i] ) ) | |
isIntMain = false; | |
if ( isIntMain == false ) | |
cout << tempNumber << " Invalid Integer" << endl; | |
else | |
cout << tempNumber << " Valid Integer" << endl; | |
cout << endl; | |
} | |
cin.ignore(); | |
cin.get(); | |
return 0; | |
} | |
bool isInt(char tempNumber) | |
{ | |
bool isInt = false; | |
for (int i = 0; i < 10; i++) | |
if ((int)tempNumber == i + 48) | |
isInt = true; | |
return isInt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment