Dec 13, 2019 at 9:38am UTC
//Example: Write a program that reads grades from a file and store them in 2x4 array. Then it finds and displays the max min of each row.
PS: file is opened
#include<iostream>
#include<fstream>
void GRADEStoArray(int grades[][4],int Row, int Col);
using namespace std;
int main(){
int grades[2][4];
int maxi,mini;
int Row=2; int Col=4;
ifstream grade;
grade.open("grades.txt");
if(grade){
GRADEStoArray(grades,Row,Col);
for(int i=0; i<Row ; i++){
for(int j=0; j<Col ; j++) {
if(grades[i][j]>maxi)
maxi=grades[i][j];
if(grades[i][j]<mini)
mini=grades[i][j];
}
}
cout<<"max grade is "<<maxi;
cout<<"min grade is "<<mini;
}
else
cout<<"File is closed \n";
return 0;
}
void GRADEStoArray(int grades[][4], int Row, int Col){
for(int i=0; i<Row ; i++){
for(int j=0; j<Col ; j++)
cout<<grades[i][j]<<" ";
cout<<endl;
}
}
Last edited on Dec 13, 2019 at 9:39am UTC
Dec 13, 2019 at 5:19pm UTC
add a cin statement the end of it, see if that helps. if so, you are running from an ide that spawns the window, shows the output, and closes before you can blink. The best fix for that is to run it from a persistent command line / console window instead.