Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
How to pass a 2D array to another function in C++?
Here the code
void results()
{
double storeScores;
for (int ii = 0; ii < NUM_ROWS; ii++)
{
cout << "Please enter 9 Numbers that you want to input for group" << ii + 1 << endl;
for (int jj = 0; jj < NUM_COLS; jj++)
{
cout << jj + 1 << " | ";
cin >> storeScores;
scores[ii][jj] = checkInput(storeScores);
}
}
}
double checkInput(double aScores){
if(aScores > 20 || aScores < 0){
cout << "Invalid value! Enter score again:" << endl;
cin >> aScores;
}
return aScores;
}
void printscores()
{
cout << " " <<endl;
cout << " " <<endl;
cout << "Sample Output:" << endl;
cout << "-----------------------------------" << endl;
cout << "pair before tr. after tr." << endl;
cout << "-----------------------------------" << endl;
}
Can ya help me to pass the array from results to printscores. i've been trying to figure this out all day
3 Answers
- 1 decade agoFavorite Answer
Here is how you can create and initialize your double ** on the heap. Use i.e. double **scores = GetDouble(NUM_ROWS, NUM_COLS) to create your array. The following prototype declares a parameter of your array: double fct(double **d). I hope that helps.
double **GetDouble(int iRows, int iCols)
{
double **dbl = new double*[iRows];
for (int i = 0; i < iRows; i++){
dbl = new double[iCols];
for (int j = 0; j < iCols; j++){
dbl[i][j]=0.0f;
}
}
return dbl;
}