473,503 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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",&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;

}
Oct 30 '08 #1
2 1468
34*******@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);
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
Oct 30 '08 #2
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.
http://frapedia.se/wiki/Information_in_English
Oct 30 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7446
by: lawrence | last post by:
If I do something like : $result = mysql_query($query); $dbArray = dbResultIntoKeyArray($result); and this is the function: function dbResultIntoKeyArray($result) {
47
12023
by: Mountain Bikn' Guy | last post by:
Take some standard code such as shown below. It simply loops to add up a series of terms and it produces the correct result. // sum numbers with a loop public int DoSumLooping(int iterations) {...
2
1265
by: ommadawn | last post by:
I am new at coding and would like to know if the following is correct: I want to be able to list information repeatedly with the same text added to it. Don't know if this is the way to do it,...
65
12506
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
2
2249
by: spacejay | last post by:
I'm programming an VB.NET application wich is using a third-party COM-DLL-module. The Module is only loaded if needed. And now my problem: My Application doesn't end correct and hang up itself....
6
3883
by: Garg | last post by:
Everytime I run my code, it shows an error that the input string is not in correct format. Could anybody tell me what is wrong with my line of code? str3 = Integer.Parse(dropBasis3.SelectedIndex...
11
2682
by: jyck91 | last post by:
// Base Conversion // Aim: This program is to convert an inputted number // from base M into base N. Display the converted // number in base N. #include <stdio.h> #include <stdlib.h>...
8
1944
by: c.lang.myself | last post by:
whenever we pass an array to function, we have to also pass its size.e.g if i am making a soritng function then void sort(int b,int size); Now I thought about using sizeof operator(macro?)...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.