Hello,
I have searched extensively, which is how i know that there are 700+ posts on conversion from char to int. However, i still appear to be stuck. I was initially using the atoi() method. Here is my code:
I was having trouble using atoi() - does it only return an integer, or does it allow storage of the value too? I would also appreciate it being pointed out where i am going wrong with my type conversion.Code:#include <iostream> #include <cstdlib> using namespace std; int main() { char aDigit[4]; int newInt = 0; for ( int i = 0; i < 5; i++ ) { cout << "Input integer " << i << " :"; cin >> aDigit[i]; //newInt = atoi(aDigit[i]); newInt = static_cast<int>(aDigit[i]); if ( newInt < 1 || newInt > 9 ) { cout << "Please input an integer between 0 and 9" << endl; i--; } } return 0; }
Many thanks in advance for your help and advice.
Regards, global