473,395 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Arrays to make and average of individual rows

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
3 4464
DeMan
1,806 1GB
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
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
1,806 1GB
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

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

Similar topics

0
by: Sara | last post by:
I am trying to find the average number of products of the set that is on rows...dynamically. For example, if I had states on rows and was looking at the average number of products, I would see...
13
by: Ben | last post by:
I have a program which is using a lot of memory. At the moment I store a lot of pointers to objects in std::vector. (millions of them) I have three questions: 1) Lets say the average Vector...
60
by: Peter Olcott | last post by:
I need to know how to get the solution mentioned below to work. The solution is from gbayles Jan 29 2001, 12:50 pm, link is provided below: >...
4
by: CC | last post by:
Hi there, I wanna compile a 6000x1000 array with python. The array starts from 'empty', each time I get a 6000 length list, I wanna add it to the exist array as a column vector. Is there any...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
4
by: Scott | last post by:
In order to give a meaning average value and minimum and maximum values, I would like to have a formula for a group of data after taking out those extremes. Can someone share your way to...
4
by: Christian Maier | last post by:
Hi After surfing a while I have still trouble with this array thing. I have the following function and recive a Segmentation fault, how must I code this right?? Thanks Christian Maier
8
by: RobcPettit | last post by:
Hi, What is the best way to use an array to find moving averages. I want to calculate a 15 day and 41 day m/a. I know my array will need to contain 12 columns, but the rows need to be dynamic. The...
5
by: jc | last post by:
Hi. I am in a situation with an engineering application involving monitoring of press operations. This involves storage of numbers for both an X and Y arrays. The number of element within the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.