hi i'm doing an exercise from C Primer Plus. the problem is this:
In the U.S. system of volume measurements, a pint is 2 cups, a cup is 8 ounces, an
ounce is 2 tablespoons, and a tablespoon is 3 teaspoons. Write a program that requests a
volume in cups and that displays the equivalent volumes in pints, ounces, tablespoons,
and teaspoons. Why does a floating-point type make more sense for this application than
an integer type?
this is the code i wrote:
Code:
#include <stdio.h>
int main(void)
{
float pint, cup, ounce, tablespoon, teaspoon;
pint = 2 * cup;
cup = 8 * ounce;
ounce = 2 * tablespoon;
tablespoon = 3 * teaspoon;
printf("How many cups? ");
scanf("%f", &cup);
printf("pints: %f -- ounces: %f -- tablespoon: %f -- teaspoon %f \n", pint, ounce, tablespoon, teaspoon );
return 0;
}
and this is the output:
How many cups? 25
pints: 0.000000 -- ounces: 0.000000 -- tablespoon: 0.000000 -- teaspoon 0.000000