Why I can't get the correct result

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • 348892813@qq.com

    Why I can't get the correct result

    I am a student learning C language, I know many of you are good at it.
    I need your help.Thank you.
    I want to type in a to choose addition, butI can't get the result.
    #include <stdio.h>
    int main()
    {
    char character;
    float fnum,snum;
    printf("Please type in a number:\n");
    scanf("%f%f",&f num,&snum);
    printf("Please type in another number:\n");
    scanf("%f",&snu m);
    printf("Enter a select character: ");
    printf("\n a for addition");
    printf("\n b for multiplication" );
    printf("\n c for division");
    scanf("%c",&cha racter);

    switch (character)
    {
    case 'a':
    printf("The sum of the number entered is %6.3f\n",fnum+s num);
    break;
    case 'b':
    printf("The product of the numbers entered is %6.3f\n",fnum*s num);
    break;
    case 'c':
    if(snum != 0.0)
    printf("The first number divided by the second is %6.3f\n",fnum/
    snum);
    else
    printf("Divisio n by zero is not allowed\n");
    break;
    }

    return 0;

    }
  • Zeppe

    #2
    Re: Why I can't get the correct result

    348892813@qq.co m wrote:
    I am a student learning C language, I know many of you are good at it.
    I need your help.Thank you.
    I want to type in a to choose addition, butI can't get the result.
    #include <stdio.h>
    int main()
    {
    char character;
    float fnum,snum;
    printf("Please type in a number:\n");
    scanf("%f%f",&f num,&snum);
    printf("Please type in another number:\n");
    scanf("%f",&snu m);
    printf("Enter a select character: ");
    printf("\n a for addition");
    printf("\n b for multiplication" );
    printf("\n c for division");
    scanf("%c",&cha racter);
    are you sure you are reading the values correctly? You won't get the
    correct result if you don't retrieve the correct values. Try to print
    them out to check them.

    Best wishes,

    Zeppe

    Comment

    • Obnoxious User

      #3
      Re: Why I can't get the correct result

      On Thu, 30 Oct 2008 01:55:23 -0700, 348892813 wrote:
      I am a student learning C language, I know many of you are good at it. I
      need your help.Thank you.
      comp.lang.c

      --
      OU
      Remember 18th of June 2008, Democracy died that afternoon.

      Comment

      Working...