hrm.. still having problems
Code:
int integer()
{ char inputdata[100];
cin >> inputdata;
return atoi(inputdata);
}
int choice(int &hp, int &hpmax, int &mp, int &mpmax, int &atk, int &def, int &pts)
{ int temp; char ans;
do{
cout << " You have " << pts << " points" <<
endl << " Attack: ";
temp = integer();
cout << endl;
if (temp > pts)
{ cout << " Not enough points." << endl;
temp = 0;
}
}while(temp > pts);
Here's what I tried:
Code:
using namespace std;
int choice(int &hp, int &hpmax, int &mp, int &mpmax, int &atk, int &def, int &pts)
{ int temp; char ans;
do{
cout << " You have " << pts << " points" <<
endl << " Attack: ";
temp = integer();
cout << endl;
if ((temp > pts) || (!cin))
{ cout << " Not enough points." << endl;
temp = 0;
}
}while((temp > pts) || (!cin));
This just gives me an error and loops forever.
Again, the problem with the way I did it, is that if I enter a letter it will assume it is 0. Any idea on how i fix?