| Gotcha (2) | |
|
hey there. im still new here,and a beginner with this C++ program. im busy with an assignment with 2D arrays. most of the questions i did get right and some only half and then one of them not at all hehe. first how do i make a tabel with string names? and then the second question is how do i determine the smallest of all in a 2D array. here is my program below #include <iostream> using namespace std; const int NUM_FRIENDS = 4; const int NUM_MODULES = 3; void getdata(int inputP[] [NUM_MODULES]) { int friends; for (int i = 0;i < NUM_FRIENDS; i++) { cout << "Enter" << NUM_MODULES << "hour interfals studied weekely on each module " << endl; for (int j = 0;j < NUM_MODULES;j++) { cin >> inputP[i][j]; } } } void showdata(const int inputP[] [NUM_MODULES]) { string friends; //headings for (int j = 0;j < NUM_MODULES;j++) { cout <<'\t'<< "ABC111"; } cout << endl; //rows. for (int i = 0;i < NUM_FRIENDS;i++) { cout << "Aggie : "; // cout << "Bruce : "; /// cout << "Cecil : "; // cout << "Danita : "; for (int j = 0;j < NUM_MODULES;j++) cout << inputP[i][j] << '\t'; cout << endl; } } int hoursLeast(const int inputP[] [NUM_MODULES]) { } void displayAverage (const int inputP[] [NUM_MODULES]) { int total; float average; cout << "the average of each module is : " << endl; for (int i = 0;i < NUM_MODULES;i++) { total = 0; cout << "Module " << i+1 << " : "; for (int j = 0;j < NUM_FRIENDS;j++) total = total + inputP[i][j]; average = float(total) / NUM_FRIENDS; cout << average << endl; } } int main () { int input[NUM_FRIENDS][NUM_MODULES]; getdata(input); showdata(input); hoursLeast(input); cout << endl; displayAverage(input); return 0; } it should look like this : ABC111 DEF222 GHI333 aggie 11 9 7 bruce 9 10 13 cecil 8 8 8 danita 12 8 9 where mine only show at the top row abc111, and the rows only aggie. when i try to change it so that all shows. its not displaying right.. im really stuck :( | |
|
Last edited on
|
|
| salman (9) | |||
should fix the first part... | |||
|
Last edited on
|
|||
| Gotcha (2) | |
| thank you ... now just to figure out the smallest hour :) | |
|
|
|