c++ - What is wrong with my do...while logic, and continue logic? -


i'm new stackoverflow, , new programming, please don't mind poor formatting of code. have 2 problems code.

  1. my continue statement, i'm using continue loop if player types 'y' or 'y', doesn't work. terminates program after only getting guess correctly, leads me to:

2.my continue counter goes past 0 without stopping, , can't see error in logic of program.

i can't see problems logic.

    #include "stdafx.h"     #include <iostream>     #include <iomanip>     #include <ctime>     #include <random>      using namespace std;      int getnumber(); //random number prototype     double getscore(); //gets score     int chances = 7; //chances guess     int main()     {     int guess = 0,          random;     char retry = 'y'; //initialize retry 'y'     cout << "this random number guessing game. " << "you guessing between 1-100."      << "you have 7 chances. luck! \n \n" << endl;       random = getnumber(); //give function variable      {      cout << random << "\n" << "\n";     chances--;      cout << "enter guess: ";     cin >> guess;          if (guess == random)         {             cout << "you have won game! " << "your score was: " << getscore();              cout << "would retry? (y or n): ";             cin >> retry;              if (retry == 'y' || retry == 'y')             {                 chances = 7;                 guess = 0;                 getnumber();                 continue; //player can retry game             }             else if (chances == 0)             {                 cout << "you have no chances left. retry? (y or n): ";                     cin >> retry;                 if (retry == 'y' || retry == 'y')                 {                     chances = 7;                     guess = 0;                     getnumber();                     continue;                 }             }                  return 0;         }         else if (guess != random)             cout << "you got wrong. \n" << "you have: " << chances << " chances left" << endl << endl;         else             cout << "incorrect input. please type number." << endl << endl;    } while (guess != random);   return 0; }   int getnumber()     {      unsigned seed = time(0); //seed random number      srand(seed);       int randnum = rand() % 10 + 1; //random number in range of 1-10      return randnum;     } 

you'll wanna take @ this

your continue statement jumping end , checking condition, guess != random, evaluates false , exits do while. need reset guess value such 0 condition evaluate true.


Comments