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 6605405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:16:49+00:00 2026-05-25T19:16:49+00:00

Here is a portion of some code I am trying to write: //Choice Based

  • 0

Here is a portion of some code I am trying to write:

//Choice Based Menu
#include <iostream.h>
#include <conio.h>
int main()
{
    char choice;
    cout<<"Menu"<<endl<<endl;
    cout<<"A. Option A"<<endl;
    cout<<"B. Option B"<<endl;
    cout<<"C. Option C"<<endl;
    cout<<"Q. Quit"<<endl;
    cout<<endl<<"Choice:\t";
    do
    {
        choice=getch();
        cout<<choice<<"\r";
        switch(choice)
        {
            case 'A':
            {
                cout<<endl<<"Option A!";
                break;
            }
            case 'B':
            {
                cout<<endl<<"Option B!";
                break;
            }
            case 'C':
            {
                cout<<endl<<"Option C!";
                break;
            }
            case 'Q':
            {
                return 0;
            }
            default:
            {
                cout<<endl<<"Invalid Choice! Please try again.";
                break;
            }
        }

    }while(1);
}

Since the loop continues indefinitely, it waits for another input option after executing the code of the previously chosen option.

Menu

A. Option A
B. Option B
C. Option C
Q. Quit

Choice: A
Option A!

I want the line “Choice: A” to update with the most recently entered option every single time. And I want the output of the previously selected option (Option A!) to be replaced with the output from a newly chosen option.

I tried using ‘\r’ as you may have noticed. That does not work because it gives me a carriage return i.e. it moves back to the beginning of the line. I want it to move back only by one character, and not to the beginning of the line.

  • 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-25T19:16:50+00:00Added an answer on May 25, 2026 at 7:16 pm

    This this:

    #include <iostream.h>
    #include <conio.h>
    int main()
    {
        char choice;
        cout<<"Menu"<<endl<<endl;
        cout<<"A. Option A"<<endl;
        cout<<"B. Option B"<<endl;
        cout<<"C. Option C"<<endl;
        cout<<"Q. Quit"<<endl;
        do
        {
            choice=getch();
            cout << "\r" << "Choice:\t"; // Moved into the loop
            switch(choice)
            {
                case 'A':
                {
                    cout << "Option A!"; // No more endl
                    break;
                }
                case 'B':
                {
                    cout << "Option B!";
                    break;
                }
                case 'C':
                {
                    cout << "Option C!";
                    break;
                }
                case 'Q':
                {
                    return 0;
                }
                default:
                {
                    cout << "Invalid Choice! Please try again.";
                    break;
                }
            }
        }while(1);
        cout << endl; // New sole endl
    }
    

    This is not exactly what you want, but it’s the closest one can get with minimal rework.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I needed some help in trying to optimize this code portion ... Basically here's
I'm trying to write some metaprogramming code such that: Inheriting from some class foo<c1,
Here is a portion of my code: var styles:String = .keyword{color: #ff0000;} .comment{color: #00ff00;};
I have some code here that I have helped modified, however there is a
I'm trying to parse some XML from the USGS. Here's an example The parameterCd
Here is a portion of my app.yaml file: handlers: - url: /remote_api script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
[ edit ] For the record, here's the problem portion of the query, which
Here is my code, which takes two version identifiers in the form 1, 5,
I have a snippet of code, to calculate the width of some child items
Here is my situation... I am trying to dynamically generate a bunch of stuff

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.