0

I am given an exercise that I can't seem to understand. I am almost done with my assignment but I'm stuck on this function.

Limitations: There can only be 10 unique student ID's. There are 5 subject area of study. An a student can only take 2 subjects.

My struct.h look like this:

typedef struct student_info{
  int student_id;
  int course_id[2];
  }student;

In main.c

student info[10];

In func.c

Say I Prompt the user for a Student ID.

printf("Enter Student ID. ");
scanf("%d", &info->student[count_stud]->student_id;

User inputs 123

Then Prompt the user for a course ID.

printf("Enter Course ID. ");
scanf("%d", &info->student->course_id[count_cour];

User inputs 101

My problem lays with printing out a specific student_id and the course that student is taking. Also using a for loop I couldn't find a way to find a duplicate. I can find an id that was last inputted by the user but when I enter an id from 2 previous inputs it passes my if else statements.

Any help is appreciated.

6
  • 1
    scanf("%d", &info[count_stud].student_id);,scanf("%d", &info[count_stud].course_id[count_cour]); Commented Feb 27, 2014 at 2:49
  • Maybe if you showed these "if else" statements, and the code that seems to be giving you trouble, someone could help you. Commented Feb 27, 2014 at 2:49
  • &info->student[count_stud] is just wrong. Commented Feb 27, 2014 at 2:51
  • Sorry guys I copied it wrong. Commented Feb 27, 2014 at 3:02
  • My scantf is exactly as bluepixy suggested. I just want to be able to print out a student_id and the courses associated with that student_id. I don't know where to start. As for my duplicate error checking I will post in a different thread. One question at a time. Commented Feb 27, 2014 at 3:09

1 Answer 1

1
student info[10];

Here, info is array of 10 students so you will have to read it with index.

for(int student_count = 0; student_count < 10; student_count ++)
{    
    printf("Enter Course ID 1 for student %d. ",student_count+1);
    scanf("%d", &info[student_count].course_id[0]);

    printf("Enter Course ID 2 for student %d. ",student_count+1);
    scanf("%d", &info[student_count].course_id[1]);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.