Hey, it's me again.I've got a decent system going for my RPG now, but I have one major issue that ruins the whole thing. The problem comes from two little lines of code:
When choosing a class, if the user inputs a value that is greater than 2,147,483,647, the program will infinitely run:Code:cout << "Choose a class: Press '1' for Warrior, '2' for Ranger, or '3' for Mage.\n"; cin >> charClass;
Is there any way I can fix the overflow problem? Any help will be greatly appreciated as this problem keeps reoccurring in my programs.Code:hitPoints = rand() % 50 + 50; attack = rand() % 15 + 5; defense = rand() % 15 + 5; magic = rand() % 5 + 5; accuracy = rand() % 5 + 10; cout << "Name: " << charName << endl; cout << "Class: Warrior\n"; cout << "HP: " << hitPoints << endl; cout << "ATK: " << attack << endl; cout << "DEF: " << defense << endl; cout << "MGK: " << magic << endl; cout << "ACC: " << accuracy << endl; cout << "\nIs this information correct? (y/n) "; cin >> recreate; if (recreate != 'n' && recreate != 'y') { cout << "\nYou have entered an invalid character."; recreate = 'n'; }



LinkBack URL
About LinkBacks
I've got a decent system going for my RPG now, but I have one major issue that ruins the whole thing. The problem comes from two little lines of code:


