Hey can someone please help me with my project? I attached the instructions + .cpp file , I can't seem to get it to work correctly.
Thank you!!
Hey can someone please help me with my project? I attached the instructions + .cpp file , I can't seem to get it to work correctly.
Thank you!!
Indeed, your function calls are wrong - read up on them. You use () when calling functions and you must also pass an argument for your functions.
Since this is C++, I'd rather you try to use vector instead of built-in arrays too.
Oh and array is a keyword. Best not use that.
array is not a keyword, but it is not a particularly descriptive name since it says the obvious.Oh and array is a keyword.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
What function calls? and I used arrays cause it is the name of the project >_<
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]; //telling the user the average high temperature cout << "Average high temperature:"<<averageHigh<< endl; //telling the user the average low temperature cout << "Average low temperature:"<<averageLow<< endl; //telling the user the highest temperature cout << "Highest temperature:"<<indexHighTemp<< endl; //telling the user the lowest temperature cout <<"Lowest temperature:"<<indexLowTemp<< endl; cout<<"Name"<< 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 sumh = 0; for(int i=0; i<12; i++) sumh += array[i][0]; return sumh/12.0; } //does the math for the average low temperatures, also contains a for looop double averageLow(int array[][2]) { int suml = 0; for(int i=0; i<12; i++) suml += array[i][1]; return sum1/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]; } } return highTemp; } int indexLowTemp(int array[][2]) { int index = 0; int lowTemp = array[0][1]; for(int i=1; i<12; i++) { if(array[i][1] < lowTemp) { lowTemp = array[i][1]; index = i; } } return lowTemp; }
In this example it's fine, but consider std::vector otherwise.
What function calls????? What are these if not function calls?
You're doing it wrong - you're printing the address of the function (or if you'd used Visual Studio 2005 or another compiler, you'd get a compile error because that isn't standard!)!
std::vector is part of the STL. Very, very useful. I suggest you learn it when you have time.
A function call is when you call a function - simple enough
Code:int foo() { return 6; } int main() { int myint = foo(); // Calls function - aka function call. cout << myint; // Prints 6 to screen. cout << foo(); // Calls function - aka function call. Prints 6 to screen. cout << foo; // Prints the function ADDRESS. Where the function is located in the memory (if it compiles at all)! }
No, I'm not majoring in Programing I just had to take the class..
http://www.cprogramming.com/tutorial/lesson4.html
You can't use a tool if you don't know how to use it. Read up, friend. Functions are your friends.
I did a function program before but not with arrays
Is it something like this?
Code:int main() { int months[12][2]; getData(array[i][0],array[i][1]); averageHigh(sumh); averageLow(suml); indexHighTemp(highTemp); indexLowTemp(lowTemp); //telling the user the average high temperature cout << "Average high temperature:"<<averageHigh[sumh]<< endl; //telling the user the average low temperature cout << "Average low temperature:"<<averageLow[suml]<< endl; //telling the user the highest temperature cout << "Highest temperature:"<<indexHighTemp[highTemp]<< endl; //telling the user the lowest temperature cout <<"Lowest temperature:"<<indexLowTemp[lowTemp]<< endl; cout<<"Name"<< endl; getch (); return 0; }