Why I can't get the correct result

3

348892813

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;

}
 
Z

Zeppe

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);

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,169
Messages
2,570,918
Members
47,458
Latest member
Chris#

Latest Threads

Top