I'm designing a simple RPG just to get me started in C++ coding, however my else statement is not working, and I feel my code is bulkier than it should be. Could you wonderful people give me some tips on how to improve my code and how to fix the else statement. I am aware of the "System("cls")" hatred across everything, but I put it there because it makes it look more cleaner than other methods.
I'm still a complete novice at C++ by the way
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
int save = 0;
int menuinput;
int raceinput;
string race;
int cont1;
int main(void)
{
int save = 0;
int menuinput;
int raceinput;
string race;
int cont1;
cout << "(Insert Generic RPG Name Here) n";
if (save == 1){
cout << "Main Menun";
cout << "[1.] Continuen";
cout << "[2.] New Gamen";
cout << "[3.] Optionsn";
cin >> menuinput;
}
if (save == 0){
cout << "Main Menun";
cout << "[1.] New Gamen";
cout << "[2.] Optionsn";
cin >> menuinput;
system("cls");
}
if (menuinput == 1)
{
cout << "Please select your racen";
cout << "[1.] Humann";
cout << "[2.] Elfn";
cout << "[3.] Dwarfn";
cout << "[4.] Orcn";
cin >> raceinput;
if (raceinput == 1){
race = "Human";
cont1 = 1;
}
if (raceinput == 2){
race = "Elf";
cont1 = 1;
}
if (raceinput == 3){
race = "Dwarf";
cont1 = 1;
}
if (raceinput == 4){
race = "Orc";
cont1 = 1;
}
else {
system("cls");
cout << "Invalid Input, please try again.";
Sleep(1000);
main();
}
if (cont1 = 1){
system("cls");
cout << race;
cin >> race;
}
else
{
system("cls");
cout << "Invalid Input, please try again.";
Sleep(10000);
main();
}
}
}
EDIT: To reiterate, when I try to use the first else statement (where the main menu is present) the else statement does not activate, and immediately ends the program. The else statement message does not show. And in the second else statement, the else statement message shows, but the Sleep function does not work, it shows for about about half a millisecond then disappears.
Aucun commentaire:
Enregistrer un commentaire