HELP ME WITH MY GAME!! please

Hello there. Ive been doing some c++ in dev-c++. I started a month ago, taught myself from books and playing around with written code, the basics and i now know
computer function
computer sience and variabeldefinition (char, int, short, long, float, bool, double, long double, \n, \t, \", \\, \b.
Algorithm,pseudocode,
byte, bit, etc etc
many choiceoperators (this is important so you know what way to reply)
anyhow, after learning all that i started skipping through sides of the book looking for the command to go back in a program, the reason i want to know this is because im trying to make a text based game to help my learning of c++, i will keep on learning by this book (wich i have) while making this game, ive come about 100 codes forward, lets skip to my question:
i want to know how to back up in a program
for exampel: if the program is giving 3 option at the start for example: start, option, info. If someone chooses info i dont know how to help the get back to the choices. Another question is when i come to the end of the game or wherever ive place system("CLS"); i need to post system("PAUSE"); so i doesnt automaticly skip. however, wherever i post this it says press any button to skip, how can i prevent this from showing up whilst maintaining the "non skipping". I'm 13 years old and im from sweden so try to explain the code with very easy language.
this is part of the code (a part where i use the system("PAUSE");) please help.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  system("PAUSE");
system("CLS");
    cout << "What class do you want to be?" << endl;
    cout << "Healer?" << endl;
    cout << "Fighter?" << endl;
    cout << "Magician?" << endl;
    cout << "Ranger?" << endl;
    cin >> Class;
   system("CLS");
   
if (Class == "Ranger" || Class == "ranger"){
          cout << "You have chosen the class " << Class;
          cout << " is this the class you want?\n";
}

if (Class == "Healer" || Class == "healer"){
          cout << "You have chosen the class " << Class;
          cout << " is this the class you want?\n";
}

if (Class == "Fighter" || Class == "fighter"){
          cout << "You have chosen the class " << Class; 
          cout << " is this the class you want?\n";
}

if (Class == "Magician" || Class == "magician"){
          cout << "You have chosen the class " << Class;
          cout << " is this the class you want?\n";
}
     cin >> YesorNo;
system("CLS");
if (YesorNo == "Yes" || YesorNo == "yes") {
     cout << "Good \n";       
}            

else {  // Find a way to go back steps
     cout << "Sorry, Restart to go back! \n";
}      

system("PAUSE");
return 0;
}
just use loop or goto
but everyone hates goto so i don't know...
don't use them ?

1
2
3
4
5
6
7
8
9
10
11
12
do {
	system("PAUSE");
	system("CLS");
		cout << "What class do you want to be?" << endl;
		cout << "Healer?" << endl;
		cout << "Fighter?" << endl;
		cout << "Magician?" << endl;
		cout << "Ranger?" << endl;
		cin >> Class;
	   system("CLS");
} while( Class != "Ranger" || Class != "Healer" || Class != "Fighter" || Class != "Magician" );
hmm, the code u posted is for system("PAUSE"); and if so could you explain it?
ill look up tutorials for goto's :) thanks
Lines 11-29 all do the same thing, so why do you even check what kind of class they are? If you wanted to check to see that they picked a valid class, you can use a fixed version of the broken example that rmxhaha posted.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<iostream>
#include<string>

int main() {
	std::string in,yn;
	while (1) { //loop until input yes
		for (int i=0; i<50; ++i) {std::cout << std::endl;} //clear screen
		std::cout << "What class do you want to be?" << std::endl;
		std::cout << std::endl << "Healer?" << std::endl << "Fighter?";
		std::cout << std::endl << "Mage?" << std::endl << "Ranger?";
		std::cout << std::endl << std::endl << "Input: "; 
		std::cin >> in;
		if (in=="Healer" || in=="healer" || in=="Fighter" || in=="fighter" ||
		in=="Mage" || in=="mage" || in=="Ranger" || in=="ranger") {
			std::cout << std::endl << "You have selected " << in;
			std::cout << ", is this the class you would like to play?";
			std::cout << std::endl << std::endl << "Input: ";
			std::cin >> yn;
			if (yn=="Y" || yn=="y" || yn=="Yes" || yn=="yes") {
				break;
			}
		}
	}
	std::cout << std::endl << "Confirmed ";
	std::cin >> yn; //to pause so you can see output
}

alternatively

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<iostream>
#include<string>

int main() {
	std::string in,yn;
	do { //loop until input yes
		for (int i=0; i<50; ++i) {std::cout << std::endl;} //clear screen
		std::cout << "What class do you want to be?" << std::endl;
		std::cout << std::endl << "Healer?" << std::endl << "Fighter?";
		std::cout << std::endl << "Mage?" << std::endl << "Ranger?";
		std::cout << std::endl << std::endl << "Input: "; 
		std::cin >> in;
		if (in=="Healer" || in=="healer" || in=="Fighter" || in=="fighter" ||
		in=="Mage" || in=="mage" || in=="Ranger" || in=="ranger") {
			std::cout << std::endl << "You have selected " << in;
			std::cout << ", is this the class you would like to play?";
			std::cout << std::endl << std::endl << "Input: ";
			std::cin >> yn;
		}
	} while (yn!="Y" && yn!="y" && yn!="Yes" && yn!="yes");
	std::cout << std::endl << "Confirmed ";
	std::cin >> yn; //to pause so you can see output
}


also a friendly word of advise. this is the sort of stuff i did in high school when i was trying to learn programming and it never really got me anywhere. early on in your learning consider setting more concrete goals. instead of starting a non specific goal of starting "a text based game" where your goals can conform to your skills (subconsciously even). set a goal where your skills must conform to the goal. A good place to start for me was tic-tac-to.
Last edited on
Thanks, ive quit the text based game. I got every info about c++ that i wanted, i learned quite the amount because of the game though :)
Topic archived. No new replies allowed.