C++ random 2d array with average
Can't get random numbers in range 1-100. The average is also wrong. Any advice is greatly appreciated. #include <iostream> #include <cstdlib> #include <ctime> #include <cmath> using namespace std; int main() { srand(time(NULL)); const int rows = 3; const int cols = 3; double sum = 0; int grades[rows][cols]; int row, col; for (int r = 0; r < rows; ++r) { row = rand() % 100 + 0; for (int c = 0; c < cols; ++c) { col = rand() % 100 + 0; grades[r][c] = (rand() % 100) + 0; sum += grades[r][c]; cout << sum << " "; } double average = sum / (rows + cols); cout << "Average: " << average<<endl; cout << endl; } return 0; }