• Advertisement
Sign in to follow this  

array + functions

This topic is 3771 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#include <iostream> #include <iomanip> #include <cmath> #include <cstring> #include <string> using namespace std; void getData (int m[], size int h[], size int 1[]); int averageHigh(int aH[]); int averageLow(int aL[]); int indexHighTemp(int indexH[]); int indexLowTemp (int indexL[] ); int main() { cout << "Kevin's Monthly Tempature/HIGH and LOW"<<endl; string months[12]; int HighTemp[12]; int LowTemp[12]; int i; getData (m[], size h[], size 1[]); return 0; } void getData ( int m[], int h[], int 1[] ); int i; for (int i = 0;int i < 12;int i++); { cout <<" Enter Months" << i + 1 << " : " <<endl; cin>>months; cout<<" Enter Highest Tempature for the month of " << months[0]++ << " : " << endl; cin >> HighTemp ; cout <<" Enter Lowest Tempature for the month of:" <<endl; cin >>LowTemp; } int averageHigh(int twoDim[] [2], int rows) { int i; int sum = 0; for (i = 0; i < rows; i++) sum = sum + twoDim[0]; if (rows > 0) return sum / rows; else return 0; } int averageLow(int twoDim[][2], int rows) { int i; int sum = 0; for (i = 0; i < rows; i++) sum = sum + twoDim[1]; if(rows > 0) return sum /rows; else return 0; } int indexHighTemp(int twoDim[][2], int rows) { int i; int highIndex = 0; for (i = 1; i <rows; i++) if (twoDim[highIndex][0] < twoDim [0]) highIndex = 1; return highIndex; } int indexLowTemp(int twoDim[] [2], int rows) { int i; int LowIndex = 0; for (i = 1; i <rows; i++) if (twoDim[LowIndex] [1] > twoDim [1] ) LowIndex = i ; return LowIndex; } these are my errors 1>------ Build started: Project: TempArray, Configuration: Debug Win32 ------ 1>Compiling... 1>TempArray.cpp 1>c:\users\ben\programming codes\temparray\temparray\temparray.cpp(11) : error C2061: syntax error : identifier 'size' 1>c:\users\ben\programming codes\temparray\temparray\temparray.cpp(24) : error C2144: syntax error : 'int' should be preceded by ')' 1>c:\users\ben\programming codes\temparray\temparray\temparray.cpp(24) : error C2660: 'getData' : function does not take 0 arguments 1>c:\users\ben\programming codes\temparray\temparray\temparray.cpp(24) : error C2059: syntax error : ')' 1>c:\users\ben\programming codes\temparray\temparray\temparray.cpp(27) : error C2143: syntax error : missing ')' before 'constant' 1>c:\users\ben\programming codes\temparray\temparray\temparray.cpp(27) : error C2143: syntax error : missing ';' before 'constant' 1>c:\users\ben\programming codes\temparray\temparray\temparray.cpp(27) : error C2059: syntax error : ')' 1>c:\users\ben\programming codes\temparray\temparray\temparray.cpp(29) : error C2059: syntax error : 'for' 1>c:\users\ben\programming codes\temparray\temparray\temparray.cpp(29) : error C2143: syntax error : missing ')' before ';' 1>c:\users\ben\programming codes\temparray\temparray\temparray.cpp(29) : error C2143: syntax error : missing ';' before '<' 1>c:\users\ben\programming codes\temparray\temparray\temparray.cpp(29) : error C2086: 'int i' : redefinition 1> c:\users\ben\programming codes\temparray\temparray\temparray.cpp(28) : see declaration of 'i' 1>c:\users\ben\programming codes\temparray\temparray\temparray.cpp(29) : error C2143: syntax error : missing ';' before '++' 1>c:\users\ben\programming codes\temparray\temparray\temparray.cpp(29) : error C2086: 'int i' : redefinition 1> c:\users\ben\programming codes\temparray\temparray\temparray.cpp(28) : see declaration of 'i' 1>c:\users\ben\programming codes\temparray\temparray\temparray.cpp(29) : error C2059: syntax error : ')' 1>c:\users\ben\programming codes\temparray\temparray\temparray.cpp(30) : error C2447: '{' : missing function header (old-style formal list?) 1>Build log was saved at "file://c:\Users\Ben\Programming Codes\TempArray\TempArray\Debug\BuildLog.htm" 1>TempArray - 15 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== can someone help me????

Share this post


Link to post
Share on other sites
Advertisement
1. Homework? (Not saying it is - just asking :)

2. Place your posted code in [source] tags to preserve formatting. You can edit your post using the 'edit' button in the upper-right.

Share this post


Link to post
Share on other sites
Hello,

There is a lot of things that is wrong with the program. I am not going to go through the entire list of your problems, but I will highlight certain ones. First of all, in your main function you call the getData function by passing variables that have not been declared. It should have been this instead: getData(months, HighTemp, LowTemp);. Also, in the getData function your cin parts are wrong. it should be cin>>m; cin>>h; and cin>>l. When you are trying to obtain information in a function and store it in a variable that was passed to it, you have to use the names you declared in the prototype. Therefore, in that example you have to use the m,h, and l and not months, HighTemp, and LowTemp. Also, when you write the contents of the function you do not put a semicolon at the end of the function name. For example:

//this is wrong
void someFunction ();
{
//what ever the contents is
}

//this is correct
void someFunction()
{
//what ever the contents is
}



There is a lot more stuff wrong in your code. I will advise you to go back on reread on functions and functions with parameters, because you are incorrectly using them. I hope some other people will come and tell you have to fix the rest of your errors, because there is so many that I do not feel like going though all of them.

~Carl J. Loucius

P.S. You should use the source tags. [ source ] [ /source ] without the spaces and put your code in between there.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement