I can't do this. 5...

Asked 1 years ago, Updated 1 years ago, 97 views

Hello, I'm a freshman in high school who is starting to learn coding. The school has made a program to average scores and has been doing this for a long time I'm copying and pasting here, and all the lines are broken. Can you take that into consideration?

#include <stdio.h>
#include<stdlib.h>

int group_total_score;
float group_avg_score;

struct user {
    char name[20];
    int score[100];
    int total_score;
    float avg_score;
};

struct user user[100];

void reg_user(int i){
    printf("input first user's name: ");
    scanf("%s", user[i].name);
}
void input_score(int i) {
    printf("please input subject score of %s.\n", user[i].name);
first:
    printf("Korean\n :");
    scanf("%d", &user[i].score[1]);
    if (user[i].score[1] < 0 || user[i].score[1] > 100) {
        printf("please input again.");
        goto first;
    }
    else { 
        user[i].total_score += user[i].score[1];
        }
second:
    printf("Math\n :");
    scanf("%d", &user[i].score[2]);
    if (user[i].score[2] < 0 || user[i].score[2] > 100) {
        printf("please input again.");
        goto second;
    }
    else {
        user[i].total_score += user[i].score[2];
    }
third:
    printf("science\n :");
    scanf("%d", &user[i].score[3]);
    if (user[i].score[3] < 0 || user[i].score[3] > 100) {
        printf("please input again.");
        goto third;
    }
    else {
        user[i].total_score += user[i].score[3];
    }
fourth:
    printf("social study\n :");
    scanf("%d", &user[i].score[4]);
    if (user[i].score[4] < 0 || user[i].score[4] > 100) {
        printf("please input again.");
        goto fourth;
    }
    else {
        user[i].total_score += user[i].score[4];
    }
fifth:
    printf("Korean history\n :");
    scanf("%d", &user[i].score[5]);
    if (user[i].score[5] < 0 || user[i].score[5] > 100) {
        printf("please input again.");
        goto fifth;
    }
    else {
        user[i].total_score += user[i].score[5];
    }
sixth:
    printf("English\n :");
    scanf("%d", &user[i].score[6]);
    if (user[i].score[6] < 0 || user[i].score[6] > 100) {
        printf("please input again.");
        goto sixth;
    }
    else {
        user[i].total_score += user[i].score[6];
    }
seventh:
    printf("Aided Design\n :");
    scanf("%d", &user[i].score[7]);
    if (user[i].score[7] < 0 || user[i].score[7] > 100) {
        printf("please input again.");
        goto seventh;
    }
    else {
        user[i].total_score += user[i].score[7];
    }
eighth:
    printf("Standard Design\n :");
    scanf("%d", &user[i].score[8]);
    if (user[i].score[8] < 0 || user[i].score[8] > 100) {
        printf("please input again.");
        goto eighth;
    }
    else {
        user[i].total_score += user[i].score[8];
    }
ninth:
    printf("Computer Graphic\n :");
    scanf("%d", &user[i].score[9]);
    if (user[i].score[9] < 0 || user[i].score[9] > 100) {
        printf("please input again.");
        goto ninth;
    }
    else {
        user[i].total_score += user[i].score[9];
    }
tenth:
    printf("Programing\n :");
    scanf("%d", &user[i].score[11]);
    if (user[i].score[11] < 0 || user[i].score[11] > 100) {
        printf("please input again.");
        goto tenth;
    }
    else {
        user[i].total_score += user[i].score[11];
    }
    user[i].avg_score = (float)user[i].total_score / (float)11;
    group_avg_score += user[i].avg_score/4;
    group_total_score += user[i].total_score;
    printf("total score of %s : %d\n and his average: %.2f\n", user[i].name, user[i].total_score, user[i].avg_score);
}

int main(void) {
    int j = 4;
    for(int i = 1; i <= j ; i++);{
    The reg_user(i); /* error occurs here. */
    input_score(i);
    system("pause>cls");
    }
    printf("their total score is : %d\n and their average : %d\n", group_total_score, group_avg_score );
    return 0;
}

[Error] name lookup of 'i' changed for ISO 'for' scoping [-fpermissive] How can I correct this error?

share

2022-09-22 13:51

1 Answers

int main(void) {
    int j = 4;
    // // for(int i = 1; i <=  ; i++);{
    for(int i = 1; i <= j; i++) {
    ....

A semicolon cannot come after the for door Delete it and try it.


2022-09-22 13:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.