[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Why I can't get the correct result

348892813

10/30/2008 8:55:00 AM

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",&fnum,&snum);
printf("Please type in another number:\n");
scanf("%f",&snum);
printf("Enter a select character: ");
printf("\n a for addition");
printf("\n b for multiplication");
printf("\n c for division");
scanf("%c",&character);

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

return 0;

}
1 Answer

DJ Dharme

10/30/2008 11:36:00 AM

0

On Oct 30, 1:55 pm, 348892...@qq.com 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",&fnum,&snum); <--- You are taking two inputs here


Your First scanf call is taking two numbers