I posted an earlier question asking for help with using a validation script in my code. After a very helpful answer I was able to sort of figure out how I needed to proceed. Well, I’ve hit a big obstacle;
#include <iostream>
#include <sstream>
#include <string>
#include <ctype.h>
using namespace std;
int main()
{
unsigned __int64 input = 0;
int n, i;
char str[]="c3po...";
i=1;
n=0;
for (cout << "Input a number" << endl; cin >> input; cin.ignore(numeric_limits<int>::max(), '\n'))
{
cout << "We're parsing your input '" << input << "'\n";
if (input % 2 == 0)
{
cout << "Even!" << endl;
}
else if (input % 2 == 1)
{
cout << "Odd" << endl;
cout << "Lets make it even shall we? " << "Your new number is... " << input + 1 << endl;
}
else (isalnum(str[i]));i++;
{
cout << "We could not parse '" << input << "' as a number.\n";
}
}
system ("pause");
return 0;
}
As you can see from my code, the validation script is well, sort of working. I have some bugs I wish to iron out.
1- When I input a number, it runs though the code as it should but it also displays
Could not parse 'inputted number' as a number
obviously when a number is inputted you don’t want this to happen!
2- For the error message, it is showing the inputted number as [0]. Is this to do with using an integer? How can this be fixed?
Thanks!
your problem is quite simple, you have small mistake on this line
Your else statement ends at the semicolon and does actually nothing. Following statements will be executed every time.