1

In this program i want to take students information using structure and print the position. And in the quiz section only the best one will count out of three. Now after giving all the inputs everything works fine except in the 74th line where i am adding all the marks but when i run the code that doesn't calculate. Can someone find out where i am having the problem.

#include <stdio.h>

struct student_profile {
    char name[100];
    int ID[100];
    int Final;
    int mid;
    int attendance;
    int assignment;
    int quiz1;
    int quiz2;
    int quiz3;
    int total_marks;
} s[100];

int comparison(int quiz1, int quiz2, int quiz3) {
    int quiz_best;

    if (quiz1 > quiz2 && quiz1 > quiz3) {
        printf("Best quiz mark is: \n", quiz1);
        quiz_best = quiz1;
    } else
    if (quiz2 > quiz1 && quiz2 > quiz3) {
        printf("Best quiz mark is: \n", quiz2);
        quiz_best = quiz2;
    } else {
        printf("Best quiz mark is: \n", quiz3);
        quiz_best = quiz3;
    }
    return quiz_best;
}

int main() {
    int i, n, quiz_best;

    printf("Number of students: \n");
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        printf("\nStudent No: %d\n", i);
        printf("Name: ");
        scanf("%99s", s[i].name);
        printf("ID: ");
        scanf("%99s", s[i].ID);
        printf("Final: ");
        scanf("%d", &s[i].Final);
        printf("mid: ");
        scanf("%d", &s[i].mid);
        printf("attendance: ");
        scanf("%d", &s[i].attendance);
        printf("assignment: ");
        scanf("%d", &s[i].assignment);
        printf("quiz1: ");
        scanf("%d", &s[i].quiz1);
        printf("quiz2: ");
        scanf("%d", &s[i].quiz2);
        printf("quiz3: ");
        scanf("%d", &s[i].quiz3);
    }
    printf("\n Students Informations:\n");

    for (i = 0; i < n; i++) {
        printf("Student No: %d\n", i);
        printf("Name: %s\n", s[i].name);
        printf("ID: %d\n", s[i].ID);
        printf("Final: %d\n", s[i].Final);
        printf("mid: %d\n", s[i].mid);
        printf("attendance: %d\n", s[i].attendance);
        printf("assignment: %d\n", s[i].assignment);
        printf("quiz1: %d\n", s[i].quiz1);
        printf("quiz2: %d\n", s[i].quiz2);
        printf("quiz3: %d\n", s[i].quiz3);
        quiz_best = comparison(s[i].quiz1, s[i].quiz2, s[i].quiz3);
        printf("The best quiz mark is: %d\n", quiz_best);
        printf("Total marks: ",quiz_best+ s[i].Final+ s[i].mid+ s[i].assignment+ s[i].attendance );
    }

    return 0;
}
sun
  • 33
  • 2

1 Answers1

0

Root Cause

You just missed adding the format specifier in your printf function on the Line #74

Solution:

Modify your Line #74 as follows:

printf("Total marks: %d",quiz_best+ s[i].Final+ s[i].mid+ s[i].assignment+ s[i].attendance );
Sharad Nanda
  • 406
  • 1
  • 15
  • 27