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 would I go about adding in the user input?
My C++ code compiles, but I realized after I finished that I need to make the user choose what row and column to get the row total, column total, highest in a row, and lowest in a row.
What do I change to add that into this code?
#include <iostream>
#include <string>
#define ROWS 4
#define COLS 5
using namespace std;
int getTotal(int[][COLS], int, int);
float getAverage(int[][COLS], int, int);
int getRowTotal(int[][COLS], int, int);
int getColumnTotal(int[][COLS], int, int);
int getHighestInRow(int[][COLS], int, int);
int getLowestInRow(int[][COLS], int, int);
int main()
{
int testArray[][COLS] =
{
{ 1, 2, 3, 4, 5 },
{ 6, 7, 8, 9, 10 },
{ 11, 12, 13, 14, 15 },
{ 16, 17, 18, 19, 20 }
};
cout << "The total of the array elements is "
<< getTotal(testArray, ROWS, COLS)
<< endl;
cout << "The average value of an element is "
<< getAverage(testArray, ROWS, COLS)
<< endl;
cout << "The total of row 0 is "
<< getRowTotal(testArray, 0, COLS)
<< endl;
cout << "The total of col 2 is "
<< getColumnTotal(testArray, 2, ROWS)
<< endl;
cout << "The highest value in row 2 is "
<< getHighestInRow(testArray, 2, COLS)
<< endl;
cout << "The lowest value in row 2 is "
<< getLowestInRow(testArray, 2, COLS)
<< endl;
return 0;
}
int getTotal(int array[][COLS], int rows, int cols)
{
int sum = 0;
for(int i = 0; i < rows; i++)
{
for(int j = 0; j < cols; j++)
{
sum = sum + array[i][j];
}
}
return sum;
}
float getAverage(int array[][C
Be the first to answer this question.