By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,507 Members | 1,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,507 IT Pros & Developers. It's quick & easy.

Arrays to make and average of individual rows

P: 16
Hey guys,
This is my second post and is URGENT!!!! My final assignment is due tonite for class and I have no idea how to write this program right!
I am supposed to write a program that uses a two-dimensional array to store the highest and lowest temperatures (in farenheit) for each month of the year. The program is supposed to output the average high, average low and the highest and lowest temperatures of the year. I need it to print out as a line(for the respones that have more than one number) and just the number when I ask for only one.
This is what I have so far...some of my program is not filled in because I am not sure what to put in it!! LOL IThe "cout"'s are all the responses that must be output to the screen...PLEASE HELP!!!!
It is due by midnight tonight and it is 6:30 now...

Thanks,
Shel
================================================== =======
#include <iostream>
#include <iomanip>
using namespace std;

const int cMAX_ROWS = 2;
const int cMAX_COLS = 12;


void getData (int table[][cMAX_COLS]);

void averageHigh (const int table[][cMAX_COLS], int avgHigh);

void averageLow (const int table[][cMAX_COLS], int avgLow);

void indexHightemp (const int table[][cMAX_COLS], int indexHigh);

void indexLowtemp (const int table[][cMAX_COLS], int indexLow);


int main ()
{
int table [cMAX_ROWS][cMAX_COLS];
int avgHigh [cMAX_ROWS] = { 0 };
int avgLow;
int indexHigh;
int indexLow;


getData (table);

averageHigh (table, avgHigh);

averageLow (table, avgLow);

indexHightemp (table, indexHigh);

indexLowtemp (table, indexLow);


cout << "Enter high temperature for each month (space between): \n";
cin >> highTemps;
cout << "\n";

cout << "Enter low temperature for each month (space between): \n";
cin >> lowTemps;
cout << "\n";


cout << "Press q and then Enter to quit-->"; //
char dummy;
cin >> dummy; //Wait for input

return;
} // main

//========================getData=================== ========
// This function will fill the array.
// =================================

void getData (int table[][cMAX_COLS])
{
for (int row = 0; row < cMAX_ROWS; row++)
for (int col = 0; col < cMAX_COLS; col++)
cin >> table[row][column]);
return;
} // getData
//=====================averageHigh ==========================
// This function will calculate the average high temp for month.
// =================================

void averageHigh (const int table[][cMAX_COLS], int avgHigh)
{

for (int row = 0; row < 2; row++)
for (int column = 0; column < 12; column++)
}
cout << "Average high temperature: ";
cin >> avgHigh;
cout << "\n";

return;
// avgHigh
//==================averageLow====================== =======
// This function calculates the average low temp for month.
// =============================

void averageLow (const int table[][cMAX_COLS], int avgLow);
{
for (int row = 0; row < 2; row++)
for (int column = 0; column < 12; column++)
}
cout << "Average low temperature: ";
cin >> avgLow;
cout << "\n";

return;
// averageLow
//=================== indexhigh=============================
// This function calculates the index high temp for the month.
// ================================

void indexHightemp (const int table[][cMAX_COLS], int indexHigh)
{
some for loop goes here
}
cout << "Highest temperature: ";
cin >> indexHigh;
cout << "\n";
return;
// indexHigh
//==================== indexLow ============================
// This function calculates the index low temp for the month.
// ===================================

void indexLowtemp (const int table[][cMAX_COLS], int indexLow)
{
some for loop goes here
}

cout << "Lowest temperature: ";
cin >> indexLow;
cout << "\n";

return;
// indexLow
Dec 8 '06 #1
Share this Question
Share on Google+
3 Replies


DeMan
100+
P: 1,806
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. const int cMAX_ROWS = 2;
  6. const int cMAX_COLS = 12;
  7. const int HIGH=0;//Don't know if we'll use this but it seems like a good idea
  8. const int LOW=1;
  9.  
  10. int average(int table[]);
  11. int highest (int table[][]);
  12. int lowest(int table[][]);
  13.  
  14. int main ()
  15. {
  16.   int table [cMAX_ROWS][cMAX_COLS];
  17.   int avgHigh [cMAX_ROWS] = { 0 };
  18.   int avgLow;
  19.   int indexHigh;
  20.   int indexLow;
  21.  
  22.   for(int i=0; i<12; i++) 
  23.     cout << "Enter high temperature for next month \n";//You can use i to dispay which month we're up to if you like
  24.     cin >> table[HIGH][i];
  25.     cout << "\n";
  26.  
  27.     cout << "Enter low temperature for each month (space between): \n";
  28.     cin >> table[LOW]
  29.     cout << "\n";
  30.   }
  31.  
  32. /*you will need to add meanignfulef messages here */
  33.   cout<<average (table[HIGH]);
  34.   cout<<average (table[LOW]);
  35.   cout<<highest(table);
  36.   cout<<lowest (table);
  37.  
  38. return;
  39. } // main
  40.  
  41. //=====================averageHigh ==========================
  42. // This function will calculate the average high temp for month.
  43. // =================================
  44.  
  45. /*Notice as far as we're concerned we are dealing with a 1d array now because of the way we passed in*/
  46. int average(int table[])
  47. {
  48.   avgHigh=0;
  49.   for (int column = 0; column < 12; column++)
  50.     avgHigh = avgHigh+table[column];
  51.   }
  52.   avgHigh=avgHigh/12;
  53.   return avgHigh;
  54. }
  55. // avgHigh
  56. //=================== indexhigh=============================
  57. // This function calculates the index high temp for the month.
  58. // ================================
  59.  
  60. void indexHightemp (int table[][cMAX_COLS])
  61. {
  62.   int temp=0;
  63.   for(int i=0; <12; i++){
  64.     if( table[i]>temp) temp=teable[i];
  65.   }
  66.  
  67. return temp
  68. }
  69. // indexHigh
  70. //==================== indexLow ============================
  71. // This function calculates the index low temp for the month.
  72. // ===================================
  73.  
  74. void indexLowtemp (const int table[][cMAX_COLS], int indexLow)
  75. {
  76. some for loop goes here
  77. }
  78.  
  79. cout << "Lowest temperature: ";
  80. cin >> indexLow;
  81. cout << "\n";
  82.  
  83. return;
  84. // indexLow
  85.  
I Leave it to you to modify the indexLow method (it would be very similar to the index high). You might like to clean up some input (and there may be littlwe bit's I've missed or done wrong that need some tweaking, but at least it should give a general idea.....
Dec 8 '06 #2

P: 16
Thanks! Tried it but still have a lot of errors. Hav eto turn something in though and it is better than what I had!!

Thanks,
Shel
Dec 9 '06 #3

DeMan
100+
P: 1,806
I sm very pleased to see that you realise it is better to submit something (even if it doesn't work). You will always get (some) marks for at least having a go at the problem (and often quite a lot so long as you display an understanding of the method). Good on you.
Dec 9 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.