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

  • Home
  • SEARCH
  • 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 8620997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:43:01+00:00 2026-06-12T06:43:01+00:00

char again; do { counter = 0; while (counter < 3) { printf(Please enter

  • 0
char again;
do {
            counter = 0;
            while (counter < 3) {
               printf("Please enter a number: ");
               scanf("%d", &num);
               counter++;
               sum += num;
            }
            if (counter == 3) {
                printf("Would you like to continue? [Y]Yes [N]No:");
                scanf("%c", &again);
            } 
        }while (again == 'Y');

I can’t seem to figure out why this won’t work. If i enter Y it breaks, if I enter N it breaks. I need to loop until the user enters “N” to exit the program and no other letter.

  • 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-12T06:43:03+00:00Added an answer on June 12, 2026 at 6:43 am

    Change the scanf call to:

    scanf(" %c", &again);
    

    The trick is in the space before the %c: it instructs the scanf function to ignore any whitespace character before returning your N or Y. Otherwise you will be reading the return carriages from the previous scanf calls.

    From man 3p scanf (the POSIX one):

    A directive composed of one or more white-space characters shall be executed by reading input until no more valid input can be read, or up to the
    first byte which is not a white-space character, which remains unread.

    That is a complex function. I recommend reading the man page with care: it can do much more than most people think.

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

Sidebar

Related Questions

The following code: char filename[64]; ifstream input; cout << Please enter the filename: <<
char dict[N][M]; for(i = 0; i < N; i++) { do { printf(enter word
char a[133]; char x[4]=ccc; int line=3,count=1; //string aa; //cin>>aa; ifstream out(text); while(out.getline(a,4,':')&&(strncmp(a,x,4))) {cout<<hi; cout<<a<<endl;
{ char *a, *b; printf(%lx\n,(b-a)); } Usually works, in fact, I can't imagine it
char label[8] = abcdefgh; char arr[7] = abcdefg; printf(%s\n,label); printf(%s,arr); ====output========== abcdefgh abcdefgÅ Why
I think most would be surprised about the topic again, However I am referring
Somebody write this function void strToUpper(char *p) { while (*p) { *p = TOUPPER(*p);
Back again with another rookie question. While working on a function for my homework
I would appreciate for some C++ expertize advice on this please. I have a
I am trying to convert a char* to double and back to char* again.

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.