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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:42:14+00:00 2026-06-01T01:42:14+00:00

PROBLEM I type y as an option and it prints the text twice before

  • 0

PROBLEM I type y as an option and it prints the text twice before prompting me again when it’s supposed to only print it once.

CORRECT OUTPUT (what im supposed to get but not getting):

Do you order FISH (Y/N)? y
Fish choice (K- Haddock, T- Halibut)

Do you order FISH (Y/N)? y
Fish choice (K- Haddock, T- Halibut)

Do you order FISH (Y/N)? n

Do you order CHIPS (Y/N)? n

Do you order DRINKS (Y/N)? y
Drinks choice (S- Softdrink, C- Coffee, T- Tea)

Do you order DRINKS (Y/N)? n

WRONG OUTPUT (the output I get)

Do you order FISH (Y/N)? y
Fish choice (K- Haddock, T- Halibut)
Do you order FISH (Y/N)? Fish choice (K- Haddock, T- Halibut)
Do you order FISH (Y/N)? y
Fish choice (K- Haddock, T- Halibut)
Do you order FISH (Y/N)? Fish choice (K- Haddock, T- Halibut)
Do you order FISH (Y/N)? n
Do you order CHIPS (Y/N)? Chips choice (C- Cut, R- Ring)
Do you order CHIPS (Y/N)? n
Do you order DRINKS (Y/N)? Drinks choice (S- Softdrink, C- Coffee, T- Tea):
Do you order DRINKS (Y/N)? n

RAW SOURCE (in case you want to compile it yourself and check whats up): http://pastebin.com/raw.php?i=mZ1jVrF0

SOURCE

#include <stdio.h>
#include <string.h>

int main() {

    char fishYesNo, chipsYesNo, drinksYesNo;
    char *typeOfFood;

    do {
        typeOfFood = "fish";
        printf("Do you order FISH (Y/N)? ");
        scanf("%c", &fishYesNo);
        if (fishYesNo != 'n') {
            printf("Fish choice (K- Haddock, T- Halibut) \n");

        }
        else if (fishYesNo == 'n') {
            typeOfFood = "chips";
        }

    } while ((strcmp(typeOfFood, "fish")) == 0);

    do {
    typeOfFood = "chips";
        printf("Do you order CHIPS (Y/N)? ");
        scanf("%c", &chipsYesNo);
        if (chipsYesNo != 'n') {
            printf("Chips choice (C- Cut, R- Ring) \n");
        }
        else if (chipsYesNo == 'n') {
            typeOfFood = "drinks";
        }

    } while ((strcmp(typeOfFood, "chips")) == 0);

    do {
    typeOfFood = "drinks";
        printf("Do you order DRINKS (Y/N)? ");
        scanf("%c", &drinksYesNo);
        if (drinksYesNo != 'n') {
            printf("Drinks choice (S- Softdrink, C- Coffee, T- Tea):\n");
        }
        else if (drinksYesNo == 'n') {
            typeOfFood = "fish";
        }

    } while ((strcmp(typeOfFood, "drinks")) == 0);

}
  • 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-01T01:42:16+00:00Added an answer on June 1, 2026 at 1:42 am

    This is a well-known conceptual error in C. The comp.lang.c FAQ (which I suggest you read) has a lot of information on this and other gotchas.

    Explanation of what’s happening in your code (comp.lang.c FAQ list · Question 12.18b):

    You wanted scanf %c to read a single character, and it tried to, but
    when you tried to type that single character at it, before the rest of
    the input system would accept it, you had to hit the RETURN key, too.
    scanf read only the one character, but that extra newline was still
    sitting in an input buffer somewhere, and it’s that extra newline
    (seemingly representing a phantom blank line) which was received by
    your later input call.

    How to deal with it, from a review of scanf‘s problems (comp.lang.c FAQ list · Question 12.20):

    It’s nearly impossible to deal gracefully with all of these potential
    problems when using scanf; it’s far easier to read entire lines (with
    fgets or the like), then interpret them, either using sscanf or some
    other techniques.

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

Sidebar

Related Questions

Is there a problem with this type of implementation to wait for a batch
I've got a Schroedinger's Cat type of problem here -- my program (actually the
Has anyone an idea how the type inference problem E > hd (cons 1
Has anyone seen this type of IE display problem? Example http://xs133.xs.to/xs133/08465/ie_problem910.jpg.xs.jpg Note that it
My particular problem: I have a string which specifies an aribitrary type in a
I have a problem with an MS Chart chart type column. If there are
The problem exists in my editme.aspx page. Error 1 The type 'editme' already contains
I have a problem with reflection. I need to find the type that instantiates
Im having a problem with python.. I have a binary tree node type: class
Summary of the problem: For some decimal values, when we convert the type from

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.