Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6380087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:13:19+00:00 2026-05-25T02:13:19+00:00

I created a text-based game to help improve my C++ skills since I am

  • 0

I created a text-based game to help improve my C++ skills since I am very new to it. I’m trying to learn the basics n’ all.

Here is the program. In the switch statement, if a person were to select “3” it would broadcast an Error saying you can only select “1” or “2”.
** The issue is the program continues and doesn’t make the person RECHOOSE the selection. It goes right to Difficulty selecting.

What method do I use to force the program to halt until player chooses valid selection?

Thanks!

#include <iostream>
using namespace std;

int main()
{
cout << "\tWelcome to my text based game!\n";
char userName[100];
cout << "\nPlease enter your username: ";
cin >> userName;
cout << "Hello, " << userName << "!\n\n";

cout << "Please pick your race: \n";
cout << "1 - Human\n";
cout << "2 - Orc\n";
int pickRace;
cout << "Pick your race: ";
cin >> pickRace;

switch (pickRace)
{
    case 1:
        cout << "You picked the Human race." << endl;
        break;
    case 2:
        cout << "You picked the Orc race." << endl;
        break;
    default:
        cout << "Error - Invalid input; only 1 or 2 allowed!" << endl;
}

int difficulty;
cout << "\nPick your level difficulty: \n";
cout << "1 - Easy\n";
cout << "2 - Medium\n";
cout << "3 - Hard\n";

cout << "Pick your level difficulty: ";
cin >> difficulty;

switch (difficulty)
{
    case 1:
        cout << "You picked Easy" << endl;
        break;
    case 2:
        cout << "You picked Medium" << endl;
        break;
    case 3:
        cout << "You picked Hard" << endl;
        break;
    default:
        cout << "Error - Invalid input, only 1,2 or 3 are allowed" << endl;
}

return 0;

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:13:20+00:00Added an answer on May 25, 2026 at 2:13 am

    Use a do ... while loop, like this

    int pickRace;
    do
    {
      cout << "Please pick your race: \n";
      cout << "1 - Human\n";
      cout << "2 - Orc\n";
      cout << "Pick your race: ";
      cin >> pickRace;
      switch (pickRace)
      {
        case 1:
          cout << "You picked the Human race." << endl;
          break;
        case 2:
          cout << "You picked the Orc race." << endl;
          break;
        default:
          cout << "Error - Invalid input; only 1 or 2 allowed!" << endl;
          break;
      }
    }
    while (pickRace != 1 && pickRace !=2);
    

    This will keep on looping while the condition at the bottom is true (i.e. while they haven’t picked a valid option).

    One other comment. Since you are new you should really get into the habit of using string not char arrays. Char arrays will get you into all sorts of trouble in the future, so start using strings now. There’s no point in learning bad habits.

    #include <string>
    
    string userName;
    cout << "\nPlease enter your username: ";
    cin >> userName;
    cout << "Hello, " << userName << "!\n\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a text-based game in Java similar to Zork and
I'm trying to create a text-based game on the Windows phone. My thought is
I am writing a high-score sub-routine for a text-based game. Here's what I have
I'm currently working on a little text-based game after watching the new Tron movie
Alright let me explain myself here: I am making an online text based game.
I'm trying to create a text based Clojure game (inspired by Land of Lisp).
I'm attempting to create a text-based version of this game . Code: #include <iostream>
I am attempting to create a text-based adventure game for class, but I have
Background: I created a checkers game engine in ruby , originally with a text
I wanted to create a text based browser game, so how should I go

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.