3 Replies - 265 Views - Last Post: 02 May 2011 - 01:12 AM Rate Topic: -----

#1 gruffy  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 106
  • Joined: 28-April 11

my variable doesnt seem to catch and keep the highest score...

Posted 01 May 2011 - 06:11 PM

hi all and thanks for reading this

my variable doesnt seem to catch and keep the highest score...

when you go through the program, it doesnt seem to catch the highest user entered score, its weird cos im not good at this yet, im just chucking code at it but nothing as come from it....
would really appreciate a few pointers or nudges in the right direction, or a solution but definatley informing me of where ive gone wrong .
many thanks for reading this
gruffy :)

#include <stdio.h>
#define BIG 100

/* Declare an array to hold expenses, and a counter variable */

int grades[4], i,big, low;
int count, sum, avg;
main()
{
/* Input data from keyboard into array */
printf("Please enter your students marks to find out average, highest and lowest\n\n");
for (count = 0; count < 20; count++)
{
printf("Enter Grade %d: ", count);
scanf("%d", &grades[count]);
sum=sum + grades[count];
avg=sum / 20;
big=grades[0];
{
if(grades[count]>BIG)
big=grades[count];
else
if(grades[count]<low)
low=grades[count];
}
printf("\nLargest Number is=%d\nSmallest Number is=%d ",big,low);

}


printf("\n\nThe sum of all the grades is: %d", sum);
printf("\nThe Average grade is: %d\n\n", avg);

}



Is This A Good Question/Topic? 0
  • +

Replies To: my variable doesnt seem to catch and keep the highest score...

#2 EarthShaker  Icon User is offline

  • D.I.C Head

Reputation: 55
  • View blog
  • Posts: 186
  • Joined: 16-March 11

Re: my variable doesnt seem to catch and keep the highest score...

Posted 01 May 2011 - 06:24 PM

That's because you're setting big value to grades[0] each time the program loops.

line 18: big=grades[0];

Put that before your for loop.

This post has been edited by EarthShaker: 01 May 2011 - 06:26 PM

Was This Post Helpful? 0
  • +
  • -

#3 EarthShaker  Icon User is offline

  • D.I.C Head

Reputation: 55
  • View blog
  • Posts: 186
  • Joined: 16-March 11

Re: my variable doesnt seem to catch and keep the highest score...

Posted 01 May 2011 - 06:29 PM

Also, I believe int grades[4] and for (count = 0; count < 20; count++) will cause a runtime error.

This post has been edited by EarthShaker: 01 May 2011 - 06:30 PM

Was This Post Helpful? 0
  • +
  • -

#4 gruffy  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 106
  • Joined: 28-April 11

Re: my variable doesnt seem to catch and keep the highest score...

Posted 02 May 2011 - 01:12 AM

thanks guys, amazingness from the dedicated help dudes of this forum, any non member passers by , join this forum , they are here to help. !
Thankyou,Thankyou,Thankyou EARTHSHAKER :)
so very much appreciated
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1