hi all master...can help me with calculation for average in array? im blank..doing search but not helping me..sorry...all week script is same? i want get average for each week..tq

program use:
Dev-C++ 5.0 beta 9.2 (4.9.9.2) with Mingw/GCC 3.4.2

PURPOSE
To solve programming problems using two-dimensional arrays.

REQUIREMENT / ASSIGNMENT QUESTION
Write a program to read Air Pollution Index (API) as an input from the user and store the data in a two-dimensional array. Your program should calculate the average API for each of the four weeks. Example of API readings are given in the table below.
Mon Tue Wed Thus Fri Sat Sun Average
Week 1 88 43 56 78 98 102 105 ??
Week 2 101 110 115 130 78 77 56 ??
Week 3 44 67 89 45 33 45 33 ??
Week 4 100 189 201 55 34 67 88 ??

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185`` `````` #include #include #include #include #include using namespace std; int main() { int array[4][7] = { //declare array 4x7 {1,2,3,4,5,6,7}, {8,9,10,11,12,13,14}, {15,16,17,18,19,20,21}, {22,23,24,25,26,27,28}, }; int sum = 0; //set all day to 0 for(int y = 0; y < 7; y++){ //loop for days for(int x=0; x<4; x++){ //loop for week array[x][y]=0; } } printf("Air Pollution Index (API)\n"); printf("\n\t : The value in 4 x 7 Array table : \n"); printf("Week 1, please key in your data from Monday - Sunday \n"); { cout<<"Week 1 \n"; cout<<"Monday \n"; cin>>array[1][1]; cout<<"Tuesday \n"; cin>>array[1][2]; cout<<"Wednesday \n"; cin>>array[1][3]; cout<<"Thursday \n"; cin>>array[1][4]; cout<<"Friday \n"; cin>>array[1][5]; cout<<"Saturday \n"; cin>>array[1][6]; cout<<"Sunday \n"; cin>>array[1][7]; sum=array[1][1]+[1][2]+[1][3]+[1][4]+[1][5]+[1][6]+[1][7]/7); cout<<"Average for Week 1 is" sum; } printf("Week 2, please key in your data from Monday - Sunday \n"); { cout<<"Week 2 \n"; cout<<"Monday \n"; cin>>array[2][1]; cout<<"Tuesday \n"; cin>>array[2][2]; cout<<"Wednesday \n"; cin>>array[2][3]; cout<<"Thursday \n"; cin>>array[2][4]; cout<<"Friday \n"; cin>>array[2][5]; cout<<"Saturday \n"; cin>>array[2][6]; cout<<"Sunday \n"; cin>>array[2][7]; sum=array[2][1]+[2][2]+[2][3]+[2][4]+[2][5]+[2][6]+[2][7]/7); cout<<"Average for Week 2 is" sum; } printf("Week 3, please key in your data from Monday - Sunday \n"); { cout<<"Week 3 \n"; cout<<"Monday \n"; cin>>array[3][1]; cout<<"Tuesday \n"; cin>>array[3][2]; cout<<"Wednesday \n"; cin>>array[3][3]; cout<<"Thursday \n"; cin>>array[3][4]; cout<<"Friday \n"; cin>>array[3][5]; cout<<"Saturday \n"; cin>>array[3][6]; cout<<"Sunday \n"; cin>>array[3][7]; sum=array[3][1]+[3][2]+[3][3]+[3][4]+[3][5]+[3][6]+[3][7]/7); cout<<"Average for Week 3 is" sum; } printf("Week 4, please key in your data from Monday - Sunday \n"); { cout<<"Week 4 \n"; cout<<"Monday \n"; cin>>array[4][1]; cout<<"Tuesday \n"; cin>>array[4][2]; cout<<"Wednesday \n"; cin>>array[4][3]; cout<<"Thursday \n"; cin>>array[4][4]; cout<<"Friday \n"; cin>>array[4][5]; cout<<"Saturday \n"; cin>>array[4][6]; cout<<"Sunday \n"; cin>>array[4][7]; sum=array[4][1]+[4][2]+[4][3]+[4][4]+[4][5]+[4][6]+[4][7]/7); cout<<"Average for Week 4 is" sum; } cout("Air Pollution Index (API) table:\r\n"); cout("Week 1 2 3 4 5 6 7 average"); cout(" ---------------------------------------); system(¡§PAUSE ¡¨); getch(); return 0; //add in the last line } ``````

sample that i want similar like this:

http://www.java2s.com/Code/Cpp/Data-Structure/Defineandinitiateatwodimensionalarray.htm
Last edited on
error compile log

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253`` ``````Compiler: Default compiler Executing g++.exe... g++.exe "C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp" -o "C:\Users\PuteraDanPuteri\Documents\Untitled5.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp: In function `int main()': C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:61: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:61: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:61: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:61: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:61: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:61: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:61: error: expected `;' before ')' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:63: error: expected `;' before "sum" C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:97: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:97: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:97: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:97: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:97: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:97: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:97: error: expected `;' before ')' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:99: error: expected `;' before "sum" C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:131: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:131: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:131: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:131: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:131: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:131: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:131: error: expected `;' before ')' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:133: error: expected `;' before "sum" C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:167: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:167: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:167: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:167: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:167: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:167: error: expected primary-expression before '[' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:167: error: expected `;' before ')' token C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:169: error: expected `;' before "sum" C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:175: error: no match for call to `(std::ostream) (const char[35])' C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:176: error: no match for call to `(std::ostream) (const char[47])' C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:177: error: missing terminating " character C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:180: error: stray '\161' in program C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:180: error: stray '\167' in program C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:180: error: stray '\161' in program C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:180: error: stray '\168' in program C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:180: error: `PAUSE' undeclared (first use this function) C:\Users\PuteraDanPuteri\Documents\Untitled5.cpp:180: error: (Each undeclared identifier is reported only once for each function it appears in.) Execution terminated ``````
Last edited on
Topic archived. No new replies allowed.