C/function
Expert: Narendra - 6/24/2004
QuestionDear Sir,
Function is my weakest area in C. I did this question. Convert inches to cm using function. (1 inch =2.54cm.) then write a prog that enable user to key in the measure in inches, then calls the conversion functin n print out the measurement in cm.
Here are my coding. Please help me.You've been a great help in my other exercises. Can you see what is wrong with my coding and explain the mistakes and correct it?
#include<stdio.h> /*Prototype declarations*/
float getNum(void);
float conversion(float x);
void printnumber(float x);
int main(void)
{
float a;
float b; /*Local definitions*/
a=getNum();
b=(2.540000*a);
printnumber(b);
return 0;
}
float getNum(void)
{
float numIn;
printf("Enter the number to be converted:");
scanf("%f",&numIn);
return numIn;
}
float conversion(float x)
{
return (x*2.540000);
}
void printnumber(float x)
{
printf("The number in centimeter is:%f\n",x);
return;
}
and here are the warnings:
C:\Documents and Settings\Dzurihan Yusoff\Desktop\Assignment C\question3.c(18) : warning C4244: '=' : conversion from 'double ' to 'float ', possible loss of data
C:\Documents and Settings\Dzurihan Yusoff\Desktop\Assignment C\question3.c(37) : warning C4244: 'return' : conversion from 'double ' to 'float ', possible loss of data
AnswerI compiled your code on gcc with all the warning flags enabled. There is no warnings or errors!
Also, I don't see any problem in the code. It is working fine.
May be the compiler you are using is not ANSI compliant. If possible try to compile on another compiler (on windows) and see if you get the same warnings again.
Get back if the problem persists....
-ssnkumar