Click here to Skip to main content
15,891,673 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#include <stdio.h>

	struct COURSE{
 	char code[100];
	char name[100];
	char lecturer[100];
	int credit_hour;
};
	struct STUDENT_REC{
	char name[100];
	int gpa;
	int total_hours;
	struct ch_cs1;
 	struct ch_cs2;
 	struct ch_cs3;
	struct ch_cs4;
	struct ch_cs5;
	struct ch_cs6;
	struct ch_cs7;
	struct ch_cs8;
	struct ch_cs9;
	struct ch_cs10;
};
	

	void input_student_data(struct student_struct *st_rec);

	int computed_gpa(int average);

int main(void)
{
	struct student_struct student_record;
	
		{
		input_student_data(&student_record);
		
		printf("Student Name    :%s\n",student_record.student_name);
		printf("Subject Code    :%s\n",student_record.subject_code);
		printf("Subject Name    :%s\n",student_record.subject_name);
		printf("Lecturer Name   :%s\n",student_record.lecturer_name);
		printf("Credit Hour     :%s\n",student_record.credit_hour);
		printf("\nSubject Code  :%s\n",student_record.subject_code);
		printf("Subject Name    :%s\n",student_record.subject_name);
		printf("Lecturer Name   :%s\n",student_record.lecturer_name);
		printf("Credit Hour     :%s\n",student_record.credit_hour);
		printf("\nSubject Code  :%s\n",student_record.subject_code);
		printf("Subject Name    :%s\n",student_record.subject_name);
		printf("Lecturer Name   :%s\n",student_record.lecturer_name);
		printf("Credit Hour     :%s\n",student_record.credit_hour);
		printf("\nSubject Code  :%s\n",student_record.subject_code);
		printf("Subject Name    :%s\n",student_record.subject_name);
		printf("Lecturer Name   :%s\n",student_record.lecturer_name);
		printf("Credit Hour     :%s\n",student_record.credit_hour);
		printf("\nSubject Code  :%s\n",student_record.subject_code);
		printf("Subject Name    :%s\n",student_record.subject_name);
		printf("Lecturer Name   :%s\n",student_record.lecturer_name);
		printf("Credit Hour     :%s\n",student_record.credit_hour);
		printf("\nSubject Code  :%s\n",student_record.subject_code);
		printf("Subject Name    :%s\n",student_record.subject_name);
		printf("Lecturer Name   :%s\n",student_record.lecturer_name);
		printf("Credit Hour     :%s\n",student_record.credit_hour);
		printf("\nSubject Code  :%s\n",student_record.subject_code);
		printf("Subject Name    :%s\n",student_record.subject_name);
		printf("Lecturer Name   :%s\n",student_record.lecturer_name);
		printf("Credit Hour     :%s\n",student_record.credit_hour);
		printf("\nSubject Code  :%s\n",student_record.subject_code);
		printf("Subject Name    :%s\n",student_record.subject_name);
		printf("Lecturer Name   :%s\n",student_record.lecturer_name);
		printf("Credit Hour     :%s\n",student_record.credit_hour);
		printf("\nSubject Code  :%s\n",student_record.subject_code);
		printf("Subject Name    :%s\n",student_record.subject_name);
		printf("Lecturer Name   :%s\n",student_record.lecturer_name);
		printf("Credit Hour     :%s\n",student_record.credit_hour);
		printf("\nSubject Code  :%s\n",student_record.subject_code);
		printf("Subject Name    :%s\n",student_record.subject_name);
		printf("Lecturer Name   :%s\n",student_record.lecturer_name);
		printf("Credit Hour     :%s\n",student_record.credit_hour);

		
		printf("GPA             :%c\n",(student_record.gpa));
		}
	return 0;
}

	void input_student_data(struct student_struct *s)
	{	
		printf("Enter Student Name   :");
		gets(s->student_name);
		printf("Enter Subject Code   :");
		gets(s->subject_code);
		printf("Enter Subject Name   :");
		gets(s->subject_name);
		printf("Enter Lecturer Name  :");
		gets(s->lecturer_name);
		printf("Enter credit hour for course 1  :");
		scanf("%d",  &s->ch_cs1);
		printf("\n");
		gets(s->student_name);
		printf("Enter Subject Code   :");
		gets(s->subject_code);
		printf("Enter Subject Name   :");
		gets(s->subject_name);
		printf("Enter Lecturer Name  :");
		gets(s->lecturer_name);
		printf("Enter credit hour for course 2  :");
		scanf("%d",  &s->ch_cs2);
		printf("\n");
		gets(s->student_name);
		printf("Enter Subject Code   :");
		gets(s->subject_code);
		printf("Enter Subject Name   :");
		gets(s->subject_name);
		printf("Enter Lecturer Name  :");
		gets(s->lecturer_name);
		printf("Enter credit hour for course 3  :");
		scanf("%d",  &s->ch_cs3);
		printf("\n");
		gets(s->student_name);
		printf("Enter Subject Code   :");
		gets(s->subject_code);
		printf("Enter Subject Name   :");
		gets(s->subject_name);
		printf("Enter Lecturer Name  :");
		gets(s->lecturer_name);
		printf("Enter credit hour for course 4  :");
		scanf("%d",  &s->ch_cs4);
		printf("\n");
		gets(s->student_name);
		printf("Enter Subject Code   :");
		gets(s->subject_code);
		printf("Enter Subject Name   :");
		gets(s->subject_name);
		printf("Enter Lecturer Name  :");
		gets(s->lecturer_name);
		printf("Enter credit hour for course 5  :");
		scanf("%d",  &s->ch_cs5);
		printf("\n");
		gets(s->student_name);
		printf("Enter Subject Code   :");
		gets(s->subject_code);
		printf("Enter Subject Name   :");
		gets(s->subject_name);
		printf("Enter Lecturer Name  :");
		gets(s->lecturer_name);
		printf("Enter credit hour for course 6  :");
		scanf("%d",  &s->ch_cs6);
		printf("\n");
		gets(s->student_name);
		printf("Enter Subject Code   :");
		gets(s->subject_code);
		printf("Enter Subject Name   :");
		gets(s->subject_name);
		printf("Enter Lecturer Name  :");
		gets(s->lecturer_name);
		printf("Enter credit hour for course 7  :");
		scanf("%d",  &s->ch_cs7);
		printf("\n");
		gets(s->student_name);
		printf("Enter Subject Code   :");
		gets(s->subject_code);
		printf("Enter Subject Name   :");
		gets(s->subject_name);
		printf("Enter Lecturer Name  :");
		gets(s->lecturer_name);
		printf("Enter credit hour for course 8  :");
		scanf("%d",  &s->ch_cs8);
		printf("\n");
		gets(s->student_name);
		printf("Enter Subject Code   :");
		gets(s->subject_code);
		printf("Enter Subject Name   :");
		gets(s->subject_name);
		printf("Enter Lecturer Name  :");
		gets(s->lecturer_name);
		printf("Enter credit hour for course 9  :");
		scanf("%d",  &s->ch_cs9);
		printf("\n");
		gets(s->student_name);
		printf("Enter Subject Code    :");
		gets(s->subject_code);
		printf("Enter Subject Name   :");
		gets(s->subject_name);
		printf("Enter Lecturer Name  :");
		gets(s->lecturer_name);
		printf("Enter credit hour for course 10  :");
		scanf("%d",  &s->ch_cs10);
	}

  	int computed_gpa(int gpa)
		{
			char grade;
			if(gpa >=90)
				grade = '4';
			else if(gpa >=80)
				grade = '3';
			else if(gpa >=70)
				grade = '2';
			else if(gpa >=60)
				grade = '1';
			else
				grade = '0';
	return grade;
}


may i know why it just show the last input only? 1-9 input did not show out
Posted
Comments
Albert Holguin 28-Apr-11 22:11pm    
Its not an exact repost, now that I look closer, but don't think you're understanding structures and the need for separating code into functions.

Since its not an exact repost, I'll try to lead you in the right direction:

C++
struct STUDENT_REC{
    char name[100];
    int gpa;
    int total_hours;
    struct ch_cs1; //<-- What kind of structure is this? You're declaring that its a struct but not what type.
    struct ch_cs2;
    struct ch_cs3;
    struct ch_cs4;
    struct ch_cs5;
    struct ch_cs6;
    struct ch_cs7;
    struct ch_cs8;
    struct ch_cs9;
    struct ch_cs10;
};


This code is clearly repeating, make a function to do so, then loop through all the course:
C++
printf("Enter Subject Code   :");
gets(s->subject_code);
printf("Enter Subject Name   :");
gets(s->subject_name);
printf("Enter Lecturer Name  :");
gets(s->lecturer_name);
printf("Enter credit hour for course 1  :");
scanf("%d",  &s->ch_cs1);
printf("\n");


...And, arrays of structures are also legal, so a cleaner implementation (that'll allow the looping later):
struct STUDENT_REC{
    char name[100];
    int gpa;
    int total_hours;
    struct COURSE courses[10];
};
 
Share this answer
 
v4
your code
MIDL
printf("Enter credit hour for course 9  :");
        scanf("%d",  &s->ch_cs9);
        printf("\n");


try this in every line:

MIDL
printf("\n Enter credit hour for course 9 :");
                  scanf("%d",&s->ch_cs9);
 
Share this answer
 
Comments
Albert Holguin 28-Apr-11 22:32pm    
Removing the newline???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900