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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:29:34+00:00 2026-05-22T19:29:34+00:00

If the user selects 1 or 2, function doesn’t run. Any suggestions? #include <iostream>

  • 0

If the user selects 1 or 2, function doesn’t run. Any suggestions?

#include <iostream>
using namespace std;

void getTitle();
void getIsbn();

int main()
{
    int choice = 0;      // Stores user's menu choice

    do
    {
        // Display menu
        cout << "             Main Menu\n\n\n";

        // Display menu items
        cout << "   1. Choose 1 to enter Title.\n";
        cout << "   2. Choose 2 to enter ISBN.\n";
        cout << "   3. Choose 3 to exit.\n";

        // Display prompt and get user's choice
        cout << "   Enter your choice: ";
        cin  >> choice;

        // Validate user's entry
        while (choice < 1 || choice > 3)
        {
            cout << "\n   Please enter a number in the range 1 - 3. ";
            cin  >> choice;
        }

        switch (choice)
        {
        case 1:
            getTitle();
            break;
        case 2:
            getIsbn();
            break;
        }
    } while (choice != 3);

    return 0;
}

void getTitle()
{
    string title;
    cout << "\nEnter a title: ";
    getline(cin, title);
    cout << "\nTitle is " << title << "\n\n\n";
}

void getIsbn()
{
    string isbn;
    cout << "\nEnter an ISBN: ";
    getline(cin, isbn);
    cout << "\nISBN is " << isbn << "\n\n\n";
}
  • 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-22T19:29:35+00:00Added an answer on May 22, 2026 at 7:29 pm

    The functions should certainly get called. What will happen, though, is that the newline generated when you press “Enter” to type the number will get returned by the getline(), and the function will return without really prompting you. You need to clear that newline. You can use ignore() to do this: add cin.ignore(); immediately after reading in choice to ignore the one character.

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

Sidebar

Related Questions

I have a function that, when the user selects one or more items, it
I'm stuck with a function that doesn't want to animate... I'm using the latest
I have a function that presents the user a combo-box. def select_interface(interfaces) list_box :items
When a user selects a file in a web page I want to be
Suppose a user selects a file in a dialogue box, and the app then
When a user selects a file, I want another file field to appear. It
Background story: when a user selects a portion of text in a text field
I have an application where the user selects the dates of a first statement
I have a form in which the user selects a few items to display
I have a program in which a user selects a row in a Datagrid

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.