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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:20:59+00:00 2026-06-17T08:20:59+00:00

I’m trying to create the following structure for a C++ program in the terminal:

  • 0

I’m trying to create the following structure for a C++ program in the terminal:

Menu:
   [1] Add Number
   [2] View Numbers
   [3] View Average

[CHOICE 1] 
   - Add a Number to array
   - Once finished, show Menu again so user can select another action
[CHOICE 2] 
   - View all numbers in array
   - Once finished, show Menu again so user can select another action
[CHOICE 3] 
   - View average of all numbers in array
   - Once finished, show Menu again so user can select another action

I’m not sure exactly how to set this up. When the user inputs each menu item’s respective number, the corresponding information appears. That’s easy enough, using if statements to look for the user’s inputted number.

However, my problem comes when I try to show the menu again so the user can select another action. I recognize some sort of loop is necessary here but I’m not sure how to go about it.

Can you help me set up a basic structure of how to start this? I’d really appreciate it.

  • 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-06-17T08:21:00+00:00Added an answer on June 17, 2026 at 8:21 am

    Break down your menu entries into functions to keep everything clean and easy to grasp (for now).

    This can be expanded a lot, creating some kind of menu handling etc, but I’d just stick to something like this:

    void mainmenu() {
        int choice;
        do {
            std::cout << "Menu\n[1] -> Add Number\n[2] -> View Numbers\n[3] -> View Average\n[0] -> Quit" << std::endl;
            std::cin >> choice;
            // now perform actions based on the choice
            switch (choice) {
            case 1:
                addanumber();
                break;
            case 2:
                printnumbers();
                break;
            case 3:
                printaverage();
                break;
            }
        } while (choice); // loop as long as the choice isn't 0 (i.e. user wants to exit)
    }
    

    As Kerrek mentioned in a comment, this doesn’t really check whether the user actually picked any integer value at all. This makes the code a bit more complicated, but in general would be good practice (as thing scan get nasty, if you ignore such things):

    Replace cin >> choice; above with this:

    if (!(std::cin >> choice)) {
        choice = -1; // if input provide an invalid choice so the menu just shows again
        // also clear the input buffer of leftovers
        std::cin.clear(); // clear the buffer
        std::cin.ignore(1000, '\n'); // read any leftover chars till a line break (user hit return key)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have an array which has BIG numbers and small numbers in it. I
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am confused How to use looping for Json response Array in another Array.
I am trying to render a haml file in a javascript response like so:
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.