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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:48:23+00:00 2026-05-31T23:48:23+00:00

In function verify, I have a loop called size which is identical to the

  • 0

In function verify, I have a loop called “size” which is identical to the 3rd loop in “foodSelect” except that it works differently for some reason. It doesn’t prompt me for input first, it goes straight to the if inside of it and asks What size (L - Large, M - Medium, S - Small): Please enter S, M, or L only:. It displays the error first, then prompts me again for input. It’s weird.

Source (because it’s long): http://pastebin.com/raw.php?i=KxrMAXaU

or source here:

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

void menu();
void question (char choice[]);
void output(char *foodChoice, char *foodSelect, char *foodSize, int *foodOrderNum, float *foodSubtotal);
int verify(char *choice, char *foodChoice);

void menu() {
/*
printf("\n");
*/
    printf("\nWelcome to Sunny FISH & CHIPS!\n\n");
    printf("########     Fish :     Haddock(K) Large(L) | $5.00\n");
    printf("# FOOD #                Halibut(T) Large(L) | $4.00\n");
    printf("########     Chips:     Cut(C)     Large(L) | $2.00\n");
    printf("                        Ring(R)    Large(L) | $3.00\n");
    printf("                                            | \n");
    printf("##########   Soft Drinks(S)        Large(L) | $2.00\n");
    printf("# DRINKS #   Coffee(C)             Large(L) | $1.75\n");
    printf("##########   Tea(T)                Large(L) | $1.50\n");
    printf("---------------------------------------------\n");
    printf("Note: Medium price: 80%% of large.\n");
    printf("       Small price: 60%% of large.\n");
    printf("TAX is 10%%.\n");
    printf("More than 5 fish, 10%% discount on drink.\n");
    printf("Every 10 fish purchased, get 1 free softdrink.\n");
    printf("  - size of drink is according to size of fish\n");
    printf("----------------------------------------------\n\n");
}

int verify(char *choice, char *foodChoice) 
{
    int answer, rc = -1;
    if (choice == "order") 
    {
        do {
            answer = getchar();
            if (answer == 'Y' || answer == 'y')
            { rc = 1; }
            else if (answer == 'N' || answer == 'n')
            { rc = 0; }
            if (rc == -1 && answer != -1) 
            {
                printf("Please enter y or n only: ");
                while (answer != -1 && answer != '\n')
                answer = getchar();
            } 
        } while (rc == -1 && answer != -1);
    }
    if (choice == "foodSelect") 
    {
        do {
            answer = getchar();

                if (foodChoice == "Fish")
                {
                    do {
                        answer = getchar();
                        if (answer == 'K' || answer == 'k')
                        { rc = 1; }
                        else if (answer == 'T' || answer == 't')
                        { rc = 0; }
                        if (rc == -1 && answer != -1) 
                        {
                            printf("Please enter K or T only: ");
                            while (answer != -1 && answer != '\n')
                            answer = getchar();
                        }
                    } while (rc == -1 && answer != -1);
                }
                if (foodChoice == "Chips")
                {
                    do {
                        answer = getchar();
                        if (answer == 'C' || answer == 'c')
                        { rc = 1; }
                        else if (answer == 'R' || answer == 'r')
                        { rc = 0; }
                        if (rc == -1 && answer != -1) 
                        {
                            printf("Please enter C or R only: ");
                            while (answer != -1 && answer != '\n')
                            answer = getchar();
                        } 
                    } while (rc == -1 && answer != -1);
                }
                if (foodChoice == "Drinks")
                {
                    do {
                        answer = getchar();
                        if (answer == 'S' || answer == 's')
                        { rc = 1; }
                        else if (answer == 'C' || answer == 'c')
                        { rc = 2; }
                        else if (answer == 'T' || answer == 'T')
                        { rc = 3; }
                        if (rc == -1 && answer != -1) 
                        {
                            printf("Please enter S, C, or T only: ");
                            while (answer != -1 && answer != '\n')
                            answer = getchar();
                        } 
                    } while (rc == -1 && answer != -1);
                }   
        } while (rc == -1 && answer != -1);
    }
    if (choice == "size") 
    {
        do {
            answer = getchar();
            if (answer == 'S' || answer == 's')
            { rc = 1; }
            else if (answer == 'M' || answer == 'm')
            { rc = 2; }
            else if (answer == 'L' || answer == 'l')
            { rc = 3; }
            if (rc == -1 && answer != -1) 
            {
                printf("Please enter S, M, or L only: ");
                while (answer != -1 && answer != '\n')
                answer = getchar();
            } 
        } while (rc == -1 && answer != -1);
    }
}

void question (char *choice) {

    char *choiceYesNo;
    char *foodOptions;
    char *foodChoice;
    char *foodSelect;
    char *foodSize;
    int *foodOrderNum;
    float *foodSubtotal;

    switch (choice[0]) {
        case 'f':
            foodChoice = "Fish";
            foodOptions = "(K- Haddock, T- Halibut)";
            break;
        case 'c':
            foodChoice = "Chips";
            foodOptions = "(C- Cut, R- Ring)";
            break;
        case 'd':
            foodChoice = "Drinks";
            foodOptions = "(S- Softdrink, C- Coffee, T- Tea)";
            break;
    }

    printf("\nDo you order %s? (Y/N): ", foodChoice);
        verify("order", foodChoice);
    printf("%s choice %s: ", foodChoice, foodOptions);
        verify("foodSelect", foodChoice);
    printf("What size (L - Large, M - Medium, S - Small): ");
        verify("size", foodChoice);
    printf("How many orders do you want? (>=0): ");
        scanf("%d", &foodOrderNum);
    output(foodChoice, foodSelect, foodSize, foodOrderNum, foodSubtotal);
}

void output(char *foodChoice, char *foodSelect, char *foodSize, int *foodOrderNum, float *foodSubtotal) {

    printf("\nYou ordered %s: %c - SIZE: %c   amount ordered: %d, subtotal price: %.2lf\n\n", 
    foodChoice, foodSelect, foodSize, foodOrderNum, foodSubtotal);

}



int main() {

    //menu();

    question("drinks");


}
  • 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-31T23:48:24+00:00Added an answer on May 31, 2026 at 11:48 pm

    Apart from the fact that you really shouldn’t compare the strings with == (although in this case it is unfortunately not unlikely to work because you’re only using string literals), your trouble is because the entry of choices needs the return key to be pressed. Thus when you obtain one character for the choice from the input buffer, there is still a newline left in it. Place a

    printf("answer = %d\n",answer);
    

    after the first answer = getchar(); in the loop. That will tell you that you have gotten a newline '\n' (10) [or possibly a carriage return '\r' (13), but because of the following, I believe that’s not the case] from the input buffer. In the foodSelect loop, you have an answer = getchar(); before the if-statements, and one immediately at the beginning of the do-while loops, so that clears the input buffer. But in the foodSize branch you haven’t.

    After each choice, clear the input buffer

    while((answer = getchar()) != -1 && answer != '\n);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this form with a JS function to verify that there are no
If you have a chain of functions that operate on some data, is it
I have a function that updates a user in the asp.net membership provider. <AcceptVerbs(HttpVerbs.Post)>
I have a function that gets a string passed to it. When testing the
I have a Kohana-based website and I want to verify, in a function, where
I think I have this right but I would like someone to verify that.
just a quick question. First of all, let me verify that I have the
I have a pretty complicated function which does a couple of AJAX posts on
I have this code: btn_jouer.onRelease = function () { verif = txt_email_user.text; if (txt_email_user.text
I made this function to verify a user's twitter credentials. Its running on two

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.