# Keeping the fractional part of a quotient

This is a discussion on Keeping the fractional part of a quotient within the C Programming forums, part of the General Programming Boards category; I am working on a lab problem. It is: Write a program that calculates the speed of sound (a) in ...

1. ## Keeping the fractional part of a quotient

I am working on a lab problem. It is: Write a program that calculates the speed of sound (a) in air of a given temperature T (in Fahrenheit). The formula to compute the speed in feet/second:
a = 1086 * sqrt ((5T+297)/247)
Be sure your program does not lose the fractional part of the quotient in the formula shown. As part of your solution, write and call a function that displays instructions to the program user.

I know how to do everything else but keep the fractional part. Below is my program. If anyone could help me out with this I'd really appreciate it. In another problem from this lab we used the scale function to round a number so I'm not sure if we might need to use this function again?

Code:
```#include <stdio.h>
#include <math.h>

int main (void)
{
float sound, temperature;
printf("Enter a temperature T in fahrenheit: ");
scanf("%f", &temperature);

sound = 1086 * (sqrt ((5 * temperature + 297) / 247));

printf("When the temperature is %f F, the speed of sound in the air is %f\n", temperature, sound);
return 0;
}```

2. What you have looks like it should keep the fractional parts alright, although just to be safe, I'd recommend specifying the constants as floating point numbers (5.0 instead of 5, 247.0 instead of 247, etc.).

Also, please use [CODE] tags when posting code.

3. First off, thanks for posting code! But you should use CODE tags (they save indentation and make it easier to read)

Code:
```#include <stdio.h>
#include <math.h>

int main (void)
{
float sound, temperature;
printf("Enter a temperature T in fahrenheit: ");
scanf("%f", &temperature);

sound = 1086 * (sqrt ((5 * temperature + 297) / 247));

printf("When the temperature is %f F, the speed of sound in the air is %f\n",     temperature, sound);
return 0;
}```
(isn't that better?)