This is my code. I am to read in numbers from a file which is my nums.txt.
Then we are to have the user choose what row or colum they would like to work with. I have two different functions for working with a row or column and we are suppose to find the min, max and avg of the given column/row.
I am having my problem on line 50 and 57.
statisticsR(x[i][j]); - which says invalid conversion from 'int' to 'int(*)[200]'
if anyone knows what im doing wrong please help
Then we are to have the user choose what row or colum they would like to work with. I have two different functions for working with a row or column and we are suppose to find the min, max and avg of the given column/row.
I am having my problem on line 50 and 57.
statisticsR(x[i][j]); - which says invalid conversion from 'int' to 'int(*)[200]'
if anyone knows what im doing wrong please help
Code:
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin;
#define max1 100
#define max2 200
void display();
int intalize();
int statisticsR (int x[max1][max2]);
int statisticsC (int x[max1][max2]);
int main() {
display();
return 0;
}
int intalize(){
int i,j;
int x[max1][max2];
fin.open("nums.txt");
if (!fin) cout << "file did not open";
while(!fin.eof()){
for(j=0; j<4; j++){
fin >> x[i][j];
return x[i][j]; }
cout<< endl;
i++;
}
}
void display(){
char a, r, c;
int num, i, j;
cout<< "please enter filename."<<endl;
intalize();
cout << "would you like to work with rows or columns?" <<endl;
cin>>a;
if(a ==r) {
cout << "what row?" <<endl;
cin >>num;
if(num>100) cout<< "number exceeds the array";
i=num;
statisticsR(x[i][j]);
}
if (a == c) {
cout << "what column?" << endl;
cin >>num;
if (num>200) cout << "number exceeds the array";
j=num;
statisticsC(x[i][j]);
}
if (a!=r||a!=c) cout << "please choose again" << endl;
}
int statisticsR (int x[max1][max2]){
int i, j,max, min, sum=0;
double avg=0;
for( j=1; j<200;j++){
if (x[i][j]> x[i][j-1]) max= x[i][j];
if (x[i][j]< x[i][j-1]) min= x[i][j];
sum=sum+ x[i][j];
}
avg=sum/j;
cout<< "max: " <<max <<endl;
cout<< "min: "<< min<< endl;
cout <<"avg: "<<avg<<endl;
return avg;
}
int statisticsC (int x[max1][max2]){
int j, i,max, min, sum=0;
double avg=0;
for( i=1; i<100;i++){
if (x[i][j]> x[i-1][j]) max= x[i][j];
if (x[i][j]< x[i-1][j]) min= x[i][j];
sum=sum+ x[i][j];
}
avg=sum/i;
cout<< "max: " <<max <<endl;
cout<< "min: "<< min<< endl;
cout <<"avg: "<<avg<<endl;
return avg;
Comment