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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:43:12+00:00 2026-05-26T08:43:12+00:00

#include <stdio.h> int i, party; char x = ‘ ‘; float total = 0,

  • 0
#include <stdio.h>

int i, party;
char x = ' ';
float total = 0, perCost = 0;
main(){

            switch (toupper(x)) {
                case 'A':
                    printf("Combo A: Friend Chicken with slaw [price: 4.25]");
                    perCost = 4.24;             
                    break;
                case 'B':
                    printf("Combo B: Roast beef with mashed potato [price: 5.75]");
                    perCost = 5.75;
                    break;
                case 'C':
                    printf("Combo A: Fish and chips [price: 5.25]");
                    perCost = 5.25;
                    break;
                case 'D':
                    printf("Combo A: soup and salad [price: 3.74]");
                    perCost = 3.75;
                    break;
                default:
                    perCost = 0;
                    break;
            }

    printf("Enter Party Total: ");
    scanf("%d", &party);
    for (i = 0; i < party; i++) {
            printf("Enter item ordered [A/B/C/D/X]: ");
            scanf("%c%*c", &x);
    }
    total = total + perCost;
    printf("%f\n", total);
}

What is causing my programming to not grab from the switch statement?

  • 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-26T08:43:12+00:00Added an answer on May 26, 2026 at 8:43 am

    As per the given code, when the execution first come to the switch() the value of x is ' ' , so the by executing the switch() gives perCost = 0 executing the default condition in switch() make you believe that the program din grab the switch().(Note that the execution never come back to here again)

    To achieve what you supposed, give the switch() inside the for (i = 0; i < party; i++) loop, specifically, below your scanf.

    Note that total = total + perCost; is misplaced, as of now, it wont calculate the total but only gives the perCost of the last combo you ordered.This is also supposed to be inside the loop.

    You need a #include <cctype.h> in your program.

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

Sidebar

Related Questions

#include <stdio.h> int main() { float a = 1234.5f; printf(%d\n, a); return 0; }
This part of my code works fine: #include <stdio.h> int main(){ //char somestring[3] =
#include<stdio.h> int main() { printf(He %c llo,65); } Output: He A llo #include<stdio.h> int
#include<stdio.h> void foo(int **arr) { arr[1][1]++; } main() { int arr[20][20]; printf(%d\n,arr[1][1]); foo((int**)arr); printf(%d\n,arr[1][1]);
#include <stdio.h> int main() { char read = ' '; while ((read = getchar())
#include<stdio.h> int main() { char a[5]=hello; puts(a); //prints hello } Why does the code
#include<stdio.h> void function(int); int main() { int x; printf(Enter x:); scanf(%d, &x); function(x); return
#include<stdio.h> int main() { int a,b; a=a+b; printf(%d,a); return 0; } what should be
Consider the following code: #include <stdio.h> #include <ctype.h> char* Mstrupr(char* szCad); int main() {
#include <stdio.h> #include <stdlib.h> #include <string.h> void main() { typedef int (FuncPtr)(); char asmFunc[]

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.