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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:52:34+00:00 2026-05-19T11:52:34+00:00

It automatically does the default and not any of my cases. Any idea what

  • 0

It automatically does the default and not any of my cases. Any idea what I’m doing wrong?

#include <stdio.h>
#include <math.h>

int main ()
{

    float x,y,z,p,a,h;
    int d;

    printf ("\n This program calculates Perimeter, Area, or Hypotenuse of a right triangle based on user choice\n\n\n\n");

    /* Prompt user to select which calculation is to be performed */

    printf ("If you would like to calculate Perimeter, type P\nIf you would like to calculate Area, type A\nIf you would like to calculate 
    Hypotenuse, type H\n\n") ;

    scanf ("%f,%f,%f",&p,&a,&h);


    switch(d)
    {
        case('p'):
            printf("/n You have chosen to do a perimeter calculation/n");
            printf("/n Input the two side lengths of the right triangle separated by a space/n");

            scanf("%f,%f",&x,&y);
            z = pow (x,2) + pow (y,2);
            p = x + y + z;

            printf("\nLength of side A entered=%f\n",x);
            printf("\nLength of side B entered=%f\n",y);
            printf("\nCalculated Perimeter=%f\n",p);

            break;


        case('a'):
            printf("/n You have chosen to do an area calculation/n");
            printf("/n Input the two side lengths of the right triangle separated by a space/n");

            scanf("%f,%f",&x,&y);
            z = pow(x,2) + pow(y,2);
            p = x + y + z;
            a = (x * y) / 2;

            printf("\nLength of side A entered=%f\n",x);
            printf("\nLength of side B entered=%f\n",y);
            printf("\nCalculated area=%f\n",a);

            break;


        case('h'):

            printf("/n You have chosen to do a hypotenuse calculation/n");
            printf("/n Input the two side lengths of the right triangle separated by a space/n");

            scanf("%f,%f",&x,&y);
            z = pow (x,2) + pow (y,2);

            printf("\nLength of side A entered=%f\n",x);
            printf("\nLength of side B entered=%f\n",y);
            printf("\nCalculated Hypotenuse=%f\n",z);

            break;

            default:

                printf("/n wow...how did that even happen. Please put in a valid letter next time. /n");
    }
}
  • 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-19T11:52:35+00:00Added an answer on May 19, 2026 at 11:52 am

    It looks like your scanf() call:

    scanf ("%f,%f,%f",&p,&a,&h);
    

    should be:

     scanf ("%c",&d);
    

    Why would you ever think accepting three float inputs makes sense given the text of the prompt!?

    However doing that will cause you problems with the subsequent input calls, so what you should actually do is:

    scanf ("%c",&d);
    while( d != '\n' && getchar() != '\n' ) 
    {
        // do nothing but flush to the end of the input line
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does the default destructor in C++ classes automatically delete members that are not explicitly
does core data create a sqlite database automatically? if yes, why it's not visible?
Some of our FogBugz users experience that the Screenshot tool does not start-up automatically
Does play automatically cache data? I'm trying to read this code that someone else
Does Linux automatically re-claim all memory used by an applications immediately? If so then
Why does the application restart automatically when we create a new folder under a
does anyone know how to automatically jump to the bottom of a scrollable area
Does anyone know of a good way to automatically run certain file types through
Does anyone know how to stop Visual Studio from automatically refreshing the Design view
Does .NET have anything similar to Perl arrays, which are indexed numerically but automatically

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.