im trying to check to see if a user has entered an integer. But everything im doing, even if its all letters it turns out that it says its an integer.
heres the source:
thanks in advance
heres the source:
Code:
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
using std::string;
void menu(), enter();
int main () {
enter();
return 0;
}
// promps a user to type an integer and then press enter to check if it is an integer numeral.
void enter(){
char *x;
int a;
do {
cout << "Press either a digit 0-9, or '-' to enter a character.\n";
cout << "Press [return] to finish entering characters:";
cin >> x;
string s = x;
if(!s.find("."))
a = atoi(x);
cout << '\n';
if (!a)
cout << "You did not enter an integer numeral.";
}while (!a);
cout << "Success, you entered an integer numeral!";
}