0

I'm having aproblem with my code, I would like to add another data up to 5 names with three grades each but I don't know how. This is my code

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

main()
{
unsigned char studname[30];
float prelim,midterm,final,average;
int total;

{
clrscr();
gotoxy(2,4);
printf("Please Enter Your Name: ");
gets(studname);

gotoxy(2,6);
printf("Prelim Grade: ");
gotoxy(19,6);
scanf("%f",&prelim);

gotoxy(2,8);
printf("Midterm Grade: ");
gotoxy(19,8);
scanf("%f",&midterm);

gotoxy(2,10);
printf("Final Grade: ");
gotoxy(19,10);
scanf("%f",&final);

total=prelim+midterm+final;
average=total/3;

gotoxy(2,12);
printf("Your Average is %f",average);
gotoxy(2,12);
scanf("%s",&studname);

getche();
}}

I'm not sure if I'm gonna use for loop or while. Any suggestions woud be of great help. Thanks

2
Contributors
1
Reply
16
Views
1 Year
Discussion Span
Last Post by David W
1

Firstly ...
please note that if you wish your code to be portable,
do not use <conio.h>

You can use a C struct and a typedef to create whatever data record you need.

typedef struct
{
    char* name;
    int id;
    int scores[5];

} Student;

And then in your main function ... get space to hold as many records as you need:

Student studs[100]; /* reserve space to hold 100 Student rec's */

Edited by David W

Votes + Comments
Thanks.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.