English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I compile and run...I enter test scores and the program keeps asking me to enter....it won;t stop...help.

it is the first while loop. i need it to end when the user hits Enter with no test score.
Purpose: Write a program that will find the lowest, highest, and average score for a set of test scores.
*********************************************************************/
#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;
char ac[BUFSIZ+1];

{

printf ("***********************************\n");
printf ("*****Test Score Statisics *****\n");
printf ("***********************************\n");

{

while ( score >= 0 ) {
printf("Please Enter test Score %d: ", i+1);
score = atoi(gets(ac));


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 19:41:23 · 4 answers · asked by importchef 2 in Computers & Internet Programming & Design

4 answers

// Replace this:
gets(ac);
if (ac[0] == 0) break;
score = atoi(ac);

// I'm Java/C#'er I have not touched C in years, fix it if wrong

2007-02-26 19:51:23 · answer #1 · answered by Andy T 7 · 1 0

the reson it dont exit is cuz your making sure score is always greter than zero. with the two if statments. you need to check after 'score = atoi(gets(ac));' if score is less than zero and break. and the while loop while ( score >= 0 ) should be while(true)

2007-02-26 19:49:33 · answer #2 · answered by origamix60 3 · 1 0

you need to end the while loop after you finish printing your scores

2007-02-26 19:50:19 · answer #3 · answered by Millie 4 · 1 0

enter negative number
such as -1

But there are logical errors in the program.

2007-02-26 20:55:02 · answer #4 · answered by iyiogrenci 6 · 1 0

fedest.com, questions and answers