I have a question about how to display it.

Asked 1 years ago, Updated 1 years ago, 40 views

I would like to create a c++ program that reads Korean, math, and English scores from a separate file, gives a total score, and displays 1st, 2nd, and 3rd place, but I don't know how to display 1st to 3rd place.After sorting, I would like to display 1st to 3rd place, but the image is
Attendance number score
1st place
2nd place
3rd place
I would like to
Where should I change it?
Also, if the rate is the same, 1st place (1 person, 1 more person)
2nd place
3rd place
How do I display that?

#include<stdio.h>

int main()
{
    FILE*f;
    float example_result[30], xmax, sum[10], sumdummy;
    inti,j,jmin,n;

    f = fopen("filename", "r");
    if(f==NULL){
        printf("Cannot open filename" nn");
        return1; 
    }

    for(i=0;i<30;i=i+3)
        fscanf(f, "%g", example_result[i]);

    fclose(f);

    if(n==0){
        printf("No data in filename);
        return1;
    }

    for(j=0;j<=10;j++){
        sum[j]=exam_result[3*j]+exam_result[3*j+1]+exam_result[3*j+2];
    }

    for(j=0;j<10;j=j+1){
        if(sum[j]<sum[jmin])jmin=j;
    }

    if(j!=jmin){
        sumdummy=sum[j];
        sum[j] = sum[jmin];
        sum[jmin] = sumdummy;
    }

    for(j=0;j<=3;j++){
        printf("%g", sum[j]);
    }

    return 0;
}

c++

2022-09-30 21:37

1 Answers

There are a lot of things that don't seem to work, but if you close your eyes to everything and answer only the questions in the text,

printf("1st %g", sum[0]);// is OK or not read from the body of the question
printf("2nd %g", sum[1]);
printf("3rd %g", sum[2]);

But it's going to satisfy the theme. (If you don't set the locale/language settings, you'll be worried if kanji will be displayed, but let's leave that aside.)

printf("%d %g", i+1, sum[i]); if the display is bound to use for.
(Full-width differences occur in the former code and half-width differences in the latter code.)

There has been an increase in the same rate since I wrote the above, but before implementing detailed code, the program only works as I wrote, so I have to organize it myself (this is called specification).If it's blurry, you don't even know what to do.

Is it okay to write it in one line?
If there are two people with the same percentage, will they be in second or third place?
If we all have the same rate, will we show the 2nd place or not?
(Same as 3rd place) There are so many things that you have to decide in advance.If you think about it carefully, it may come out more.Let's set the specifications for each of them.Then write the code.


2022-09-30 21:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.