c++ - Do-while loop issue: Try to develop a simple game -


well, i'm writing make dice game. tried searching dice game here none of seems answer question. isn't problem dice roll thing anyway. it's while loop. new site, found out via maximum pc magazine please bear me. new programming.

here code:

#include <iostream> #include <cstdlib> #include <ctime>  using namespace std; int main(){      srand(time(null));      int userroll = rand() % 6 + 1 ;     int computerroll = rand() % 6 + 1 ;     string yesornochoice;     string commandtothrowdie;       do{         cout << "please enter \"throw\" (lowercase) roll die: ";         cin >> commandtothrowdie;     } while(commandtothrowdie != "throw");      do{         cout << "you rolled: " << userroll << endl              << "the computer rolled: " << computerroll << endl;          if (userroll < computerroll){             cout << "you lose. try again? [yes/no]: ";          }         if (computerroll < userroll){             cout << "you win! try again? [yes/no]: ";         }         if (computerroll == userroll) {             cout << "it's draw. try again? [yes/no]: ";         }         cin >> yesornochoice;     } while(yesornochoice != "yes");       system ("pause");     return 0; } 

the problem after asking user enter choice @ end of do-while-loop program exits loop no matter enter, instead of looping throw of die.

it ends this:

screenshot of program run

i copied code , compiled , ran perfectly. doesn't make sense exactly, no issues. doesn't make sense since when "yes" entered kills it. believe want while(yesornochoice == "yes"). perhaps having != making think getting wrong behavior? also, should using if, else if, else statements, not if.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -