473,568 Members | 2,882 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",&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;

}
Oct 30 '08 #1
2 1477
34*******@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
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
7451
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
12067
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) { int result = 0; for(int i = 1;i <=iterations;i++) { result += i;
2
1273
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, but it prints out OK for me. Now, in order to get the items listed vertically, I used the 'join' Method with <br>; is this correct? The only problem...
65
12520
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 method was a piece of C code which turned out to be incorrect and incomplete but by modifieing it would still be usuable. The first method was...
2
2256
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. After I have closed my application, i can see in the task manager a CPU Load about over 95%. I could verify that this only happens, if the COM Module...
6
3884
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 - 1, 10) + ";"
11
2684
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> #include <string.h> #define LENGTH 20 int temp, m, n, i, r, base10, true;
8
1951
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?) inside sort function on b and get size of b i.e by sizeof(b)/sizeof (b) but i am not getting correct result.....
0
7693
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7604
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7916
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7660
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6275
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.