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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:41:26+00:00 2026-05-26T07:41:26+00:00

I want the do while loop to check to see if the entered input

  • 0

I want the do while loop to check to see if the entered input is R OR P. I think it is checking for both and when I get to that part when I run, it pauses for a minute and then I get "CPU Limit Exceeded (core dumped). On another related note, am I in danger of breaking something?

/************************************************/
/* Name: servcode                               */
/* Description: Get service type                */
/* Parameters: N/A                              */
/* Return Value: servcode                       */
/************************************************/

char servcode()
{
  char servcode = 'a';   // Define variable for service code
  char serviceyn = 'n';  // Define variable for user verify
  int i = 1;             // Define variable for sentinel loop

  do {
    cout << "\n" << "\n" << "Please enter your service code, [R]egular or [P]remium: " << "\n";
    cin >> servcode;
    while ((servcode != 'R', 'P') && (i < 3));
    {
        cout << "\n" << "Error - invalid service code, please try again.";
        cout << "\n" << "Please enter your service code: ";
        cin >> servcode;
        i++;
        if (i == 3)
        {
            cout << "\n" << "Too many invalid attempts, program terminating." << "\n"
             << "Have a nice day. " << "\n" << "\n";
            exit (0);
        } //end if
    } //end while
    cout << "\n" << "You entered: " << servcode << "\n"
     << "Is that correct? [y,n]";
    cin >> serviceyn;
  } while (serviceyn != 'y'); // end do/while loop

  return servcode;
}
  • 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-26T07:41:27+00:00Added an answer on May 26, 2026 at 7:41 am

    The correct syntax is:

    while (servcode != 'R' && servcode != 'P' && i < 3)
    

    Note the expanded comparison and the removal of the semicolon at the end:

    1. (servcode != 'R', 'P') is valid C++ but doesn’t do what you’re expecting it to do;
    2. the semicolon makes the statement into a loop with an empty body, so it continues executing forever since the loop condition never changes.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just want a quick way (and preferably not using a while loop)of createing
I want to write a loop in Java that firs starts up and goes
I have a long running loop I want to run in the background with
Inside MySQL I have written a Procedure where I want to run a loop
I have a randomly generated 10x5 array that I want to check when 3
I've done something like this in pvp using while loop but I don't think
I want to check the last character of the String for characters that are
I've been looking for a while and want a way to sort a Javascript
I want a splash screen to show while the application is loading. I have
I want to play a sound while my splash screen gets data from the

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.