HELP

So I am trying to Make this RPG Text game thing and i was having the problem and the problem is is that the while loop i put in there will keep going and i have tried everything i can to make it stop when i want it any help PLEASE?!

[code] "Main" Class:

#include "Main.h"
#include <iostream>
#include "Wizard.h";
using namespace std;

int Character() {

int b;
int one = 1;
while( one == 1 ) {
int b;
cout << "Please Choose a Character." << endl;
cout << "1) Wizard" << endl;
cout << "2) Dwarf" << endl;
cout << "3) Human" << endl;
cout << "4) Cho" << endl;
cout << "Please press the number next to the corresponding character you would like to " << endl;
cout << "choose to choose that character" << endl;
cin >> b;
system("CLS");
if( b == 1 ) {
int z;
int health = 10, attackdmg = 1, attackspeed = 1, manaregen = 1, mana = 10;
cout << "Here is the Wizard Class stats" << endl;
cout << "Health: " << health << endl;
cout << "Attack Dmg: " << attackdmg << endl;
cout << "Attack Speed: " << attackspeed << endl;
cout << "Mana Regen: " << manaregen << endl;
cout << "Mana: " << mana << endl;
cout << endl;
cout << "Would you like to choose this class? 1 = YES 2 = NO" << endl;
cin >> z;
system("CLS");
if( z == 1 ){
++one;
Wizard bo;
}
else
{
cout << endl;
}
}
}
return Character();
}


int main()
{
int a;
cout << "Welcome to RPG Text Game" << endl;
cout << "Press (1) to create a new game" << endl;
cout << "Press (2) to go to a saved location" << endl;
cin >> a;
system("CLS");
if( a == 1 ) {
cout << Character() << endl;

}
}

[Code] "Wizard" Class:

#include "Wizard.h"
#include <iostream>
#include <string>
using namespace std;

Wizard::Wizard(void)
{
cout << "IT WORKS!" << endl;
}


Last edited on
You have worked out how to do bold text - so now work out how to use code tags with the <> button.

IMO, this shows why beginners should not routinely use infinite loops, because they are too lazy to come up with an end condition.

This is a classic case for using a switch, have a look at this :


http://www.cplusplus.com/forum/beginner/104553/2/#msg564228


HTH
Topic archived. No new replies allowed.