2017-10-12 47 views
-1
  1. 我需要原型的幫助。
  2. 我需要求助者的幫助。
  3. 我需要幫助的功能標題。

我不知道這個網站希望我補充多少細節,但代碼說明了自己,我對前三項有困難,但由於某種原因網站需要更多上下文?C++ 2d陣列...在原型上丟失並且調用沒有在任何地方看到這個

#include <iostream> 
using namespace std; 

void fillArray(int salesSheet[][COLSIZE], int rowSize); 
// I dont know how to create prototype for 2d array 
int main() 
{ 
    const int ROWSIZE = 5, COLSIZE = 6; 
    int salesSheet[ROWSIZE][COLSIZE], a, rowSize; 

    fillArray(a[][COLSIZE], int rowSize); 
    // I don't know where I messed this up 
    // I messed up the caller too, help? 
    return 0; 
} 
void fillArray(int salesSheet[][COLSIZE], int rowSize) 
{ 
    int r, c; 
    cout <<"Enter sales report for each quarter, for your branch." << endl; 
    for (c = 0; c < COLSIZE; c++) 
    { 
     for (r = 0; r < rowSize; r++) 
      cout << "\nBranch " << c+1 << " quarterly sales figures:" 
     cin >> salesSheet[r][c]; 
    } 
} 
+0

您好,歡迎StackOverflow上。請參閱https://stackoverflow.com/help/how-to-ask,瞭解如何根據指南提出正確的問題並改進您的問題。 –

回答

0
#include <iostream> 
using namespace std; 

const int ROWSIZE = 5, COLSIZE = 6; 

void fillArray(int salesSheet[][COLSIZE]); 

int main() 
{ 
int salesSheet[ROWSIZE][COLSIZE]; 

fillArray(salesSheet); 

return 0; 
} 
void fillArray(int salesSheet[][COLSIZE]) 
{ 
int r, c; 
cout <<"Enter the sales report for each quarter, in you branches column."  
<< endl; 
for (c = 0; c < COLSIZE; c++) 
    { 
    for (r = 0; r < ROWSIZE; r++) 
     { 
      cout << "\nBranch " << c+1 << " quarterly sales figures:" ; 
      cin >> salesSheet[r][c];  
     } 
    } 
} 
+0

這個工程,在編輯和發佈之前嘗試過 - 在cin命令8x之前忘記了一個分號。感謝Alex的幫助,感謝它! –

0
#include <iostream> 
#include <malloc.h> 
using namespace std; 
const int ROWSIZE = 5, COLSIZE = 6; 
void fillArray(int*** salesSheet, int rowSize, int colSize); 

int main() 
{ 
    int** salesSheet = (int**)malloc(COLSIZE*sizeof(int*)); 
    int* arr = (int*)malloc(ROWSIZE*COLSIZE*sizeof(int)); 

    for(int i = 0; i < COLSIZE; i++) 
     salesSheet[i] = arr+i; 

    fillArray(&salesSheet, ROWSIZE, COLSIZE); 
    free(salesSheet); 
    free(arr); 
    return 0; 
} 
void fillArray(int*** salesSheet, int rowSize, int colSize) 
{ 
    int r, c; 
    cout <<"Enter sales report for each quarter, for your branch." << endl; 
    for (c = 0; c < COLSIZE; c++) 
    { 

     for (r = 0; r < rowSize; r++){ 
      cout << "\nBranch " << c+1 << " quarterly sales figures:"; 

      cin >> salesSheet[0][r][c]; 
     } 
    } 
} 
+0

試過了,它不起作用。嘗試玩幾個不同的編碼更改......並沒有什麼=/ –

+0

好吧,我看到10分鐘請 – Alex

+0

嗯,我一直在玩它,想出了這個...現在我卡在最後一行( CIN)。 –