What is wrong with --> total += rates[i][n];Code:#include <iostream> #include <iomanip> using namespace std; //chose to use #define since columns/rows are a constant in the program #define x 5 #define y 3 int main() { //declare variables double i, n, total = 0.0; float average; //declare array and set values stored in it double rates[5][3] = {{3.4, 56.7, 8.99}, {11.23, 4.67, 85.4}, {34.6, 2.4, 9.0}, {6.3, 8.0, 4.1}, {4.0, 2.0, 3.5}}; for (i = 0; i < x; i++) for (n = 0; n < y; n++) total += rates[i][n]; //end for //calculate the average of values stored in array average = (float)total/(float) x*y; //display average with two decimal places cout << fixed << setprecision(2); cout << "The average equals: " << average << endl; cin.get(); return 0; } //end of main function
Thanks in advance for taking a look at it.