C++ Write Code to Find Average for a 2d Array of Numbers
sum and average in multidimensional array
Working on an assignment. The requirement is to had a multidimensional array with 5 rows and 5 columns. The end goal is to have the program output the sum and average of each individual row. I got this far, and I believe it is correct so far. I just cannot figure out how to output the required way. Another requirement is to have the addition and average coding take place in its own function. Thanks in advance. I am new to C++ and trying to absorb all this but cannot seem to find the next thing. Can someone point me in the right direction.
| |
Last edited on
This is the actual requirements for the assignment
Create a two-dimensional array
int input[5][5]; // [row][column]; 5 rows and 5 columns
Generate 25 random numbers to populate the two-dimensional array. Please use a separate function to calculate total and average of 5 integers in each row (one function for total, one function for average) and output the results using below format.
Row 1
Total =
Average =
Row 2
Total =
Average =
Row 3
Total =
Average =
Row 4
Total =
Average =
Row 5
Total =
Average =
Okay, I changed a little and now the program will run, but the sum and average are way off
| |
also to have the code automatically change the row so I don't have to keep writing it, would I use a loop for that?
I'm sure you've already read here:
http://www.cplusplus.com/forum/beginner/1/
Don't post homework questions
Programmers are good at spotting homework questions; most of us have done them ourselves. Those questions are for you to work out, so that you will learn from the experience. It is OK to ask for hints, but not for entire solutions.
- - -
would I use a loop for that?
Definitely.
Your assignment is so self-explanatory that's hard to give further hints. You just need to follow the instruction as you can read them.
It seems you are a bit confused about global variables and function parameters.
From where you can see (= access) a global variable?
Why do we declare parameters for functions? What's their purpose?
If you can access a variable because it's global, do you need to pass it to functions anyway?
If you 'pass' a variable to a function, does it need to be global?
What about function returning values? What's their purpose?
And what about random values generator? Do you know about it?
Please have a second look to your code:
| |
Topic archived. No new replies allowed.
C++ Write Code to Find Average for a 2d Array of Numbers
Source: http://www.cplusplus.com/forum/beginner/235183/
0 Response to "C++ Write Code to Find Average for a 2d Array of Numbers"
Enregistrer un commentaire