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 %26lt;math.h%26gt;
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
#include %26lt;string.h%26gt;
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 %26gt;= 0 ) {
printf("Please Enter test Score %d: ", i+1);
score = atoi(gets(ac));
if( score %26gt; max ) { /* Find Max Score*/
max = score;
}else{
if (score %26lt; 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;
}}
How do i end this c programming loop?....am i even using the right loop?
// 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
Reply:you need to end the while loop after you finish printing your scores
Reply: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 %26gt;= 0 ) should be while(true)
Reply:enter negative number
such as -1
But there are logical errors in the program.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment