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

	struct student_struct
	{
		char student_name[100];
		char subject_code[100];
		char subject_name[100];
		char lecturer_name[100];
		int credit_hour;
		int ch_cs1;
		int ch_cs2;
		int ch_cs3;
		int ch_cs4;
		int ch_cs5;
		int ch_cs6;
		int ch_cs7;
		int ch_cs8;
		int ch_cs9;
		int ch_cs10;
		int gpa;
	};

	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 nnot show out
Posted
Comments
Manfred Rudolf Bihy 28-Apr-11 18:20pm    
This is wrong on so many levels I hardly know where to start. I hope SA will hop along and throw some pointers at you (pun definitely intended). I've given my share today, but your code mess really tops it all, I'm sorry.
Think I'll log out now and go to bed.
Albert Holguin 28-Apr-11 18:26pm    
he's very much a learner at this point... be kind :D

1 solution

That code needs to be broken up into functions, that's hardly readable.

I can see that you're overwriting subject code, name, and lecturer name over and over again.

When you define this:
char student_name[100]; //<-- String (array of characters, not array of strings)


Also, don't forget you can use structures within structures, for example:
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 COURSE course1;
 struct COURSE course2;
 struct COURSE course3;
 ...
};
 
Share this answer
 
v2
Comments
Manfred Rudolf Bihy 28-Apr-11 18:39pm    
You are right Albert maybe I was being too harsh on OP, but there is only so much I can take in one day! :)
You've definitely pointed out things OP needs to improve! 5+
Good job!
Albert Holguin 28-Apr-11 18:41pm    
I know the feeling, I've had my share of breakdowns with people... :)
Sandeep Mewara 28-Apr-11 21:26pm    
My 5! :thumbsup:
Albert Holguin 28-Apr-11 21:27pm    
thanks sandeep :)

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