I'm really new to C, and this isn't working, can someone tell me what I'm doing wrong? I'm having trouble with the variables, which I had in global before, but my teacher wants them to be local to main. My floats are
And this program works fine when "float T, speed;" is directly under the include statements.
Code:
/* Calculating speed of sound from temperature 6/18/12 (CSC-150) */
#include <stdio.h>
#include <math.h>
int direct(void)
{
//directions
printf("In this program, you will need to enter the current temperature before you can get an output.\n\n"); /* Directions */
}
float temp(T)
{
//values
printf("What is the temperature? "); /* store variable */
scanf("%f", &T);
return (T);
}
float calc(speed)
{
float T;
T = temp();
//calculation
speed=1086*(sqrt((5*T+297)/(247))); /* calculation */
return (speed);
}
int main()
{
float T, speed;
direct();
temp();
T = temp();
calc();
speed = calc(T);
//print
printf("\nThe speed of sound in the current temperature (%.1f) is %.1f.\n\n", T, speed); /*display result*/
return (0);
}
Any help would be greatly appreciated. Thanks!
~SW