How do i modify using gets?
PROGRAM DESCRIPTION:
Write a program that will find the lowest, highest, and average score for a set of test scores. The test scores may include fractional values (i.e. 99.5 is possible).
The program then asks the user for a test score, and continues to do so until he/she types only in response to the prompt. At this point, the program prints the information listed below and quits
This is the part where i get confused....so I had to use scanf...Please help to change to gets...
This is what I got so far...
#include
#include
#include
#include
main()
{
float score;
float average;
float x;
float max = 0;
float min = 1000; /*just in case there is extra credit*/
float total = 0;
float sum;
int i = 0;
{
printf ("***********************************\n");
printf ("*****Test Score Statisics *****\n");
printf ("***********************************\n");
printf("How many test scores? "); /*I couldn't stop the loop with gets. this is why I am asking.*/
scanf ("%f", &total); /* I don't know how to use gets*/
for( i = 0; i < total; i = i + 1 )
{
printf("Please Enter test Score %d: ", i+1);
scanf ("%f", &score); /*strlen and gets were confusing to me*/
/*It was hard for me to find references for this*/
if( score > max ) { /* Find Max Score*/
max = score;
}else{
if (score < min) { /* Find Min Score*/
min = score;
}
}
sum = score + sum; /* Find Sum Score*/
}
average = sum / i; /* Find Average Score*/
printf( "\n\nThe average score is %.1f\n", average);
printf( "%d Test Scores\n", i );
printf( "Maximun Test Score = %.1f\n", max);
printf( "Minimum Test Score = %.1f\n", min);
}
system("PAUSE");
return;
}
2007-02-26
09:17:51
·
2 answers
·
asked by
importchef
2
in
Computers & Internet
➔ Programming & Design