Help with arrays and while loop

This is a discussion on Help with arrays and while loop within the C Programming forums, part of the General Programming Boards category; C programming ,, I am having a problem with one of my assignments.. I have to input student ids, and ...

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    2

    Help with arrays and while loop

    C programming ,, I am having a problem with one of my assignments.. I have to input student ids, and number grades,, then have the output show me the letter grades... My code does not seem to be working correctly.... It wont fill the letter_grade array.. I cant figure out why... Here is my code....
    Code:
    #include <stdio.h>
    int main (void)
    {
    	char letter_grade[50];
    	int grade[50];
    	int student[50];
    	int i = 0, d = 0 ;
    	int class_size = 0;
    	printf("Please enter class size\n");
    	scanf("%i",&class_size);
    	while(i < class_size)
    	{
    		printf("Please enter Student ID\n");
    		scanf("%i",&student[i]);
    		printf("Please enter Student Grade\n");
    		scanf("%i",&grade[i]);
    	
    		if (grade[i] > 89)	
    			letter_grade[i] = 'A';
    		else if (grade[i] > 79)
    			letter_grade[i] = 'B';
    		else if (grade[i] > 69)
    			letter_grade[i] = 'C';
    		else if (grade[i] > 59)
    			letter_grade[i] = 'D';
    		else
    			letter_grade[i] = 'F';
    		i = i + 1;
    	 	
    	}
    	printf ("Class Size: %i\n",class_size);
    	printf("Student ID    Grade    Letter Grade\n");
    	while(d < class_size)
    	{
    		printf("%i               %i       %c\n",student[d],grade[d], letter_grade[i]);
    		++d;
    	}
    	
    	
    	return 0;	
    }

  2. #2
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    Look at your last printf statement. Particularly the index variable you have in letter_grade[].
    Code:
    while(!asleep) {
       sheep++;
    }

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    2
    you are the man,,, i hate the dumb mistakes... lol! Thanks for the help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you place two arrays in one loop?
    By blindchicken11 in forum C Programming
    Replies: 2
    Last Post: 11-13-2011, 09:10 PM
  2. Loop that contains arrays
    By christianB in forum C Programming
    Replies: 13
    Last Post: 07-20-2011, 08:58 AM
  3. help with for loop with arrays
    By jorgejags in forum C Programming
    Replies: 4
    Last Post: 11-03-2008, 06:42 PM
  4. Arrays and For Loop
    By Jack1982 in forum C++ Programming
    Replies: 9
    Last Post: 10-10-2007, 05:57 AM
  5. Loop printing arrays
    By CHurst in forum C Programming
    Replies: 2
    Last Post: 12-14-2005, 08:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21