The weight in pounds of a walleye (a species of freshwater fish) can be calculated from its length and girth in inches according to the following formula:
where scalefactor is constant and equal to 800. Using the vi editor, write a C program on the Sun cluster that:
length
and girth
printf("Enter the length of the walleye: "); scanf("%lf", &length); printf("Enter the girth of the walleye: "); scanf("%lf", &girth);
length
and girth
to compute the weight of
the walleye according to the above formula, and assigns the weight to
a variable of the appropriate type.weight
, then it can be printed as follows:
weight
is an int, use:
printf("The weight of the walleye is: %d\n", weight);
weight
is a float, use:
printf("The weight of the walleye is: %f\n", weight);
weight
is a double, use:
printf("The weight of the walleye is: %lf\n", weight);
Hints: you can copy or ftp the file prog1.c
from the pub
subdirectory of my home directory. This file contains a template with
comments sugggesting where to put various parts of your program. If you
don't use this template, you will need to have the line:
#include <stdio.h>in your program before the line:
main() {
A test case: a walleye with a length of 32 inches and a girth of 19.5 inches should weigh 15.21 pounds.
Either turn in a print out of your program, or email it to me at
wahls@psu.edu. If you email me the program, I will email you an
acknowledgement when I receive it, and will email you again with your score
and comments after the due date. Your program will be graded on
correctness and appropriate use of comments.