Firstly, Hello everyone, this will be my first time posting here and I'm just getting into programming. I've decided upon c++ as my language and currently am working on a guess the number game, slightly modified from a few I have found online. I would much rather build upon this one program for a little while before moving on just to see all of the features that can be added to some simple little game, so currently I've got the guess the number part working generating a random number based off of the time anywhere between 1 and 100. It also tells you how many times you've guessed, but I would like to add a loop to it so that the user can play the game multiple times without having to close it out each time. There just seems to be a plethora of suggestions on how to go about adding this loop and I'm not sure which is the best for this scenario so I'm posting here in hopes someone may have a good suggestion.
The program has a do while loop already in it and maybe I could incorporate what I want to do inside of that loop, I'm not entirely certain on it, because I just learned about loops the other day and haven't messed with them too much. Any advice is appreciated. Also I'm not sure if this is where I would post this sort of thing, thank you in advance.
//Random Number Guessing Game
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int num, guess, tries = 0; //defines the integers num, guess, and tries
srand(time(0)); //seed random number generator
num = rand() % 100 + 1; // random number between 1 and 100
cout << "Guess My Number Game\n\n"; //displays name of the game
do
{
cout << "Enter a guess between 1 and 100 : "; //displays text, prompting
//the player for a number between 1 and 100
cin >> guess; //this will retrieve the input from the player and proceed
//to the following if statement to determine whether their guess is too
//high or too low.
tries++;
if (guess > num)
cout << "Too high!\n\n";
else if (guess < num)
cout << "Too low!\n\n";
else
cout << "\nCorrect! You guessed it in " << tries << " guesses!\n";
//this displays text letting the player know that they have
//correctly guessed the number and in the amount of tries that it
//took.
} while (guess != num); //this is the end of the do while loop, it is
//nullified by the fact that the guess is now equal to the number generated.
cin.ignore();
cin.get();
return 0;
}