rough example
if(age == CHAR)
{
printf(" Invalid data type\n");
}
else
{
printf("asodujnao");
}
Basically a type of validation that verifies if user has input a char or int or string.
EDIT
OK i found 'is_numeric' or 'is_string' function but it dosen't properly work
This is the actual program bit
if(initial == '?') //HELP SECTION
{
system("cls");
printf("-----Help Section-----\n");
printf("Enter your first name initial.Eg.Connor would write 'C'\n\n");
help = 0;
}
if(is_numeric(initial))
{
printf("trubles");
system("pause");
}
but it comes up with
"is_numeric undeclared, first use this function."
I'm quite a noob at programming so I don't know if it's a library I'm missing or if im writing the is_numeric bit wrong
The only time something like this would be useful would be in some kind of template, which I doubt you're asking about.
The user input is going to be whatever format you specify. In this case... whatever type your 'age' variable is, that's what type the user input will be.
1 2 3 4
int age; // age will ALWAYS be an int. Regardless of what the user inputs
if( age_is_an_int ) // an if statement like this would be worthless, because
// it would always be true. 'age' is always going to be an int no matter what.
Types are fixed at compile time. If you wrote int x;
then the type of x is int forever.
validation that verifies if user has input a char or int or string.
A user can only input an int into a variable of type int. Non-numeric chars and strings will be rejected by the I/O code (cin >> or scanf or whatever you're using) - the invalid input will remain unprocessed, at which time you can try reading them into a string (strings accept all input). Or you could read into a string at first, and then examine its contents to see if an int can be made from them.
Types are very very disciplined in C++. So if u have defined x as an integer then it will be an integer forever. So I don't understand why you even need this kind o a statement!
If it were a language like python, where any variable can store anything then such a statement would be required and python does have such a statement. as its not required it does not exist!