C++ Beginner else statement not working -


i'm designing simple rpg me started in c++ coding, else statement not working, , feel code bulkier should be. wonderful people give me tips on how improve code , how fix else statement. aware of "system("cls")" hatred across everything, put there because makes more cleaner other methods.

i'm still complete novice @ c++ 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 menu\n";             cout << "[1.] continue\n";             cout << "[2.] new game\n";             cout << "[3.] options\n";             cin >> menuinput;           }          if (save == 0){             cout << "main menu\n";             cout << "[1.] new game\n";             cout << "[2.] options\n";             cin >> menuinput;             system("cls");           }          if (menuinput == 1)         {             cout << "please select race\n";             cout << "[1.] human\n";             cout << "[2.] elf\n";             cout << "[3.] dwarf\n";             cout << "[4.] orc\n";             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: reiterate, when try use first else statement (where main menu present) else statement not activate, , ends program. else statement message not show. , in second else statement, else statement message shows, sleep function not work, shows about half millisecond disappears.

this line: if (cont1 = 1){

you have = should have ==.

so, else never happens because you're not checking if cont equals 1, you're making equal.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -