This is a discussion on Arrays Dev-c++ (please helps) within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by lifeis2evil I don't understand the tutorial... It would help if you asked a specific question. Like what ...
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!
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
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; }
Yes, this looks correct. Does it work?
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
Yes it does =] lol the thing that was mostly confusing me were the arrays -_-