Simple program but I am unsure how to fix it

Beckyanne's Avatar, Join Date: Sep 2006
Newbie Member
I wonder if anyone can see where I'm going wrong? What I am trying to do is get a student name, get their two scores then it works out a grade (Pass,merit,fail) based on the addition of the two scores. Then it must loop 5 times to get 5 student names.

On the first loop everything works fine, but when it gets to the second it will display "Fail" no matter what combination of numbers I put in. Also it will not display the error message if I go over 50 (on the second attempt - works fine on the first)

I'm pretty new to this, so any helpful guidance would be greatly apprieciated

#include <stdio.h>
#include <conio.h>

void Welcome_Screen (void);
void score (void);
void Grade (void);

int i;
char name1[5][25], name2[5][25];
int score1[5], score2[5], answer[5];



//This sets the counter to 0


//Gets name and saves it
printf("\n\nPlease enter the students forename - ");
scanf("%c", name1[i]);
printf("Please enter the students surname - ");
scanf("%c", name2[i]);


//increments the do loop by one until it has done it 5 times.
while (i<5);

return 0;
void Welcome_Screen (void)
//Displays a welcome message on initialisation
	printf("\n Student Grading System");
	printf("\n\n\n\n\n\n\nPress any key to continue...");

void score (void)
//Gets first score and saves it
printf("Enter %c %c 's first score - ", name1[i], name2[i]);
scanf("%d", score1);
					if (score1[i] >50)
                   printf("The score must not be above 50");
                   goto again;

//Gets second score and saves it
printf("Enter %c %c 's second score - ", name1[i], name2[i]);
scanf("%d", score2);
					if (score2[i] >50)
                   printf("The score must not be above 50/n");
                   goto again2;
answer[i]= score1[i] + score2[i];
//calls the Grade function

void Grade (void)
	if (answer[i] <30)
		printf("\nFinal grade for %c %c - Fail", name1[i], name2[i]);
   else if (answer[i] <=60&& answer[i] >=30)
      printf("\nFinal grade for %c %c - Pass", name1[i], name2[i]);
      printf("\nFinal grade for %c %c - Merit", name1[i], name2[i]);

shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
There are quite a few errors in the program. I am mentioning the one I just saw when I looked at it.

1. scanf for string should be %s instead of %c.
2. score function you are using the variable i which is never initialized.
3. You are taking the input in score1 the scores but comparing with score1[i] where i is never initilaized.
4. Same is the case in score1
5. similar things are observed in grade function as wel.

I think the above points will help you rectify the problem you are facing.