Get the Number of Rounds

Learn how to specify the number of rounds.

What we have

We have set up a function to print the introduction of the game. This is our inventory of already created functions:

// Function to display game introduction and rules
void displayIntroductionAndRules() {
    cout << "Welcome to Rock-Paper-Scissors game!\n" << endl;
    cout << "The rules of the game are simple:" << endl;
    cout << "1. Rock beats scissors" << endl;
    cout << "2. Scissors beats paper" << endl;
    cout << "3. Paper beats rock" << endl;
}

The next step is to ask the user about the number of rounds. This specifies how many times our game will run.

What now?

We need to create a function that asks users to input the total number of rounds they want to play and store it in a variable. These are the steps we need to perform in this task:

  • Prompt the user.
  • Take the input and store it in a variable.
  • Return the variable.

Try it yourself

Write your code in the code widget below and click the “Run” button to execute your code.

If you’re unsure how to do this, click the “Show Hint” button.

Get hands-on with 1400+ tech skills courses.