473,385 Members | 1,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

need 2D array help

2
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




Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<fstream>
  3.  
  4. using namespace std;
  5. ifstream fin;
  6. #define max1 100
  7. #define max2 200
  8. void display();
  9. int intalize();
  10. int statisticsR (int x[max1][max2]);
  11. int statisticsC (int x[max1][max2]);
  12.  
  13.  
  14. int main() {
  15.  
  16.     display();
  17.  
  18.  
  19.  
  20.     return 0;
  21.  
  22. }
  23. int intalize(){
  24.     int i,j;
  25.     int x[max1][max2];
  26.     fin.open("nums.txt");
  27.     if (!fin) cout << "file did not open";
  28.     while(!fin.eof()){
  29.         for(j=0; j<4; j++){
  30.         fin >> x[i][j];
  31.         return x[i][j]; }
  32.         cout<< endl;
  33.         i++;
  34. }
  35. }
  36.  
  37. void display(){
  38.     char a, r, c;
  39.     int num, i, j;
  40.  
  41.     cout<< "please enter filename."<<endl;
  42.     intalize();
  43.     cout << "would you like to work with rows or columns?" <<endl;
  44.     cin>>a;
  45.     if(a ==r) {
  46.         cout << "what row?" <<endl;
  47.         cin >>num;
  48.         if(num>100) cout<< "number exceeds the array";
  49.         i=num;
  50.         statisticsR(x[i][j]);
  51.     }
  52.     if (a == c) {
  53.         cout << "what column?" << endl;
  54.         cin >>num;
  55.         if (num>200) cout << "number exceeds the array";
  56.         j=num;
  57.         statisticsC(x[i][j]);
  58.     }
  59.     if (a!=r||a!=c) cout << "please choose again" << endl;
  60. }
  61. int statisticsR (int x[max1][max2]){
  62.     int i, j,max, min, sum=0;
  63.     double avg=0;
  64.  
  65.     for( j=1; j<200;j++){
  66.         if (x[i][j]> x[i][j-1]) max= x[i][j];
  67.         if (x[i][j]< x[i][j-1]) min= x[i][j];
  68.         sum=sum+ x[i][j];
  69.     }
  70.     avg=sum/j;
  71.     cout<< "max: " <<max <<endl;
  72.     cout<< "min: "<< min<< endl;
  73.     cout <<"avg: "<<avg<<endl;
  74.     return avg;
  75. }
  76. int statisticsC (int x[max1][max2]){
  77.     int j, i,max, min, sum=0;
  78.     double avg=0;
  79.  
  80.     for( i=1; i<100;i++){
  81.         if (x[i][j]> x[i-1][j]) max= x[i][j];
  82.         if (x[i][j]< x[i-1][j]) min= x[i][j];
  83.         sum=sum+ x[i][j];
  84.     }
  85.     avg=sum/i;
  86.     cout<< "max: " <<max <<endl;
  87.     cout<< "min: "<< min<< endl;
  88.     cout <<"avg: "<<avg<<endl;
  89.     return avg;
Apr 25 '07 #1
3 1227
Ganon11
3,652 Expert 2GB
You call your functions like this:

Expand|Select|Wrap|Line Numbers
  1. statisticsR(x[i][j]);
which passes the function x[i][]j which is an integer value. But your functions are expecting a 2d array, not an integer. Try

Expand|Select|Wrap|Line Numbers
  1. statisticsR(x);
Apr 25 '07 #2
nmadct
83 Expert
What Ganon11 said, plus it's good style to use capital letters for your symbolic constants (MAX1, not max1) so that they don't look like variable names.
Apr 25 '07 #3
krunk
2
thanks a lot. It fixed the errors in my program
Apr 25 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Nathan Rose | last post by:
Here's my problem. I am reading from a text file using this: if (!file_exists($file)) { echo "Don't exist\n"; return false; } $fd = @fopen($file, 'r'); if (!is_resource($fd))
4
by: KellyH | last post by:
Hi, I hope someone can point me in the right direction. I'll get it out of the way: Yes, I am a college student. No, I am not looking for anyone to do my homework, just looking for help. I have...
3
by: Tommy Lang | last post by:
I am working on this project and I need some help/pointers/comments to get me started, I am stuck. The program will be used to store information in an array while it is running. I need to store...
3
by: ash | last post by:
Hey I am new, but I don't have time to intruduce myself yet. I am intro to C++ and this is a programme I have to write. all the direction are here, It will be very nice of someone to figure this...
23
by: vinod.bhavnani | last post by:
Hello all, I need desperate help Here is the problem: My problem today is with multidimensional arrays. Lets say i have an array A this is a 4 dimensional static array.
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only...
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
5
by: SpreadTooThin | last post by:
If you are deriving a new class from another class, that you must (I assume) know the initializer of the other class. So in myClass import array class myClass(arrary.array): def...
1
by: javabeginner123 | last post by:
i have a java prob, and i have to solve it fast, but i'm just getting to know it, so plz help me solve it with full code completed, thanks so much. the prob is to create a monter fight and there is...
3
by: jac130 | last post by:
the program runs, and user is prompted via inputbox to enter an integer-this is the size of the array, then the user fills the array with that many values...but as the user enters the values, i need...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.