I need a way to convert a variable to an int or to ascii code, tried atoi, static_cast, didnt work very well... The objective is to detect if the user inserted any character other than a number, a number smaller than 0 or larger than 5, and send a message if so...
Here is the program with one of my tries...
#include<cstdlib>
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
while(1)
{
back:
cout << "Insert two numbers" << endl;
int num1, num2;
cin >> num1 >> num2;
int a = static_cast<int> (num1);
int b = static_cast<int> (num2);
if ( ( a <= -1 ) || ( a > 5 ) || ( b <= -1 ) || ( b > 5) )
{
cout << "Incorrect input" << endl;
goto back;
}
if ( fim(tabuleiro) ) break; //please dont mind this, this is a small part of a bigger program
}
}
Please note that im quite new at programing so if anyone has any tips i would apreciate it =)
Thank You.