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
#include <iostream>
#include <fstream>
usingnamespace 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;
}
#include <iostream>
#include <fstream>
usingnamespace 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;
}
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.