in this code I want to know if two numbers are Int Or String :
#include <iostream>
using namespace std;
class calculate{
private:
bool checkNumbers(int num1, int num2){
if(isdigit(num1) && isdigit(num2)){
return true;
}else{
return false;
}
}
public:
void sum(int x, int y){
bool chek=checkNumbers(x, y);
if(chek==true){
cout<< "yes it is Number"<< endl;
}else{
cout<< "Nope! String"<<endl;
}
}
};
int main()
{
calculate calulate;
calulate.sum(3, 2);
return 0;
}
But after run code, I just see Nope! String , it mean it is string. who know what is wrong? I checked numbers with isdigit and I just sent two numbers
calulate.sum(3, 2);
but nothing!! thanks
isdigit(2)is false.isdigit('2')is true. It's not clear to me what you are trying to do here, and howisdigitis relevant to that. Say, could you show an example where you expect your program to print"Nope! String"?