Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 12-10-2007
robwhit
Quote:

Originally Posted by lifeis2evil
I don't understand the tutorial...

It would help if you asked a specific question. Like what you don't understand about functions.
• 12-10-2007
Elysia
It would also help to get a grasp of the language before you use it. You don't drive a car before you know how to operate it!
• 12-11-2007
lifeis2evil
is this correct?

Code:

```#include <iostream> #include <conio.h> using namespace std; //the function prototypes void getData(int array[][2]); double averageHigh(int array[][2]); double averageLow(int array[][2]); int indexHighTemp(int array[][2]); int indexLowTemp(int array[][2]); int main() {     int months[12][2];         getData(months);   //telling the user the average high temperature     cout << "Average high temperature:"               << averageHigh(months) << endl;     //telling the user the average low temperature     cout << "Average low temperature:"               << averageLow(months) << endl;       //telling the user the highest temperature     cout << "Highest temperature:"               << indexHighTemp(months)  << endl;         //telling the user the lowest temperature     cout << "Lowest temperature:"               << indexLowTemp(months)  << endl;                 getch ();     return 0; } void getData(int array[][2]) {     /* asks the user to input the highest and lowest temperatures     and contains the for loop to store it and a counter.*/         cout << "Please enter highest temperatures for each month." << endl;     for(int i=0; i<12; i++)         cin >> array[i][0];       cout << "Please enter lowest temperatures for each month." << endl;     for(int i=0; i<12; i++)       cin >> array[i][1];      } //does the math for the average high temperatures double averageHigh(int array[][2]) {     int sumHigh = 0;         for(int i=0; i<12; i++)         sumHigh += array[i][0];     return sumHigh/12.0; } //does the math for the average low temperatures, also contains a for looop double averageLow(int array[][2]) {     int sumLow = 0;         for(int i=0; i<12; i++)         sumLow += array[i][1];     return sumLow/12.0; } //a nested for loop to find the highest and lowest temperature int indexHighTemp(int array[][2]) {     int highTemp = 0;         for(int i=0; i<12; i++)     {         if(array[i][0] > highTemp)         {             highTemp = array[i][0];                     }     }     getch();     return highTemp; } int indexLowTemp(int array[][2]) {     int lowTemp = array[0][1];        for(int i=1; i<12; i++)     {         if(array[i][1] < lowTemp)         {             lowTemp = array[i][1];                     }     }     getch();     return lowTemp; }```
• 12-12-2007
Elysia
Yes, this looks correct. Does it work?
• 12-12-2007
lifeis2evil
Yes it does =] lol the thing that was mostly confusing me were the arrays -_-
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12