problem with loops and file

Hi. So I need to find which student has the most "10s"(which is the best mark). Im given the info from txt file:
3
4 10 9 8 9
3 7 6 7
6 10 9 6 7 10 5
The first number - how many students are there.
Then the first number in every line - how many grades doest the person have
After that num ber goes the specific marks of the student. Im not sure how the keep the 'd' value and compare the amount of "10s" of each person to find the one with most of those. Might be just a stupid mistake

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 #include <iostream>
#include <fstream>
using namespace std;
int main ()
{
     int n, m ,m1, d=0;
     ifstream fd ("given.txt");
     ofstream fr ("results.txt");
     fd >> n;
     for (int i = 1; i = n; i++){
        fd >> m;
        d=0;
        for (int x = 1; x = m; x++){
            fd >> m1;
            if (m1 == 10){
                d++;
            }
        }
     }fr << n << "student has " << d << "10s" << endl;

fr << "student:" <<<  <<"has the most 10s";
     return 0;
     }
Last edited on
Here are some obvious errors:

Lines 10,13: You're using the assignment operator (=), not the comparison operator (== or <=) in your termination condition.

Line 21: Your output statement is bogus. There is no <<< operator. You're missing a term.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <fstream>
using namespace std;

int main ()
{   int n, m ,m1, d=0;
    int most_tens = 0;      //  Count of most 10s
    int best_student = 0;  

    ifstream fd ("given.txt");
    ofstream fr ("results.txt");
    fd >> n;
    for (int i = 1; i <= n; i++)    // Use <=
    {   fd >> m;
        d=0;
        for (int x = 1; x <= m; x++)    //  Use <=
        {   fd >> m1;
            if (m1 == 10){
                d++;
            }
        }
        if (d > most_tens)
        {  best_student = i;
            most_tens = d;
         }
        //  Moved inside loop            
        fr << "Student " << i << " has " << d << "10s" << endl;            
     }
     fr << "Student: " << best_student << " has the most 10s";
     return 0;
}

Last edited on
Yes i know im missing it. I just didnt know what to put there, so i left space. Dont know if it should be a new variable or an old one from previous parts of program.
Last edited on
Topic archived. No new replies allowed.