Having a problem with undeclared identifiers

I know that I have sum listed as int sum but when I go to debug it shows up as undeclared identifier. I'm having the same issue with total_properties in Case 5 as well. Here is the code. Any help or suggestions would be greatly appreciated.

#include <iostream>
#include <cstdlib>

using namespace std;

//Select the menu needed
int getMenuItem() {
cout << "\nMenu:" << endl <<
"1. Enter rent amounts:" << endl <<
"2. Display rents:" << endl <<
"3. Sort rent amounts from low to high." << endl <<
"4. Total rents" << endl <<
"5. Display memory locations" << endl <<
"6. Exit" << endl <<
"Enter an option: ";

int option, sum;

cin >> option;
return option;

}

//Enter the rent from the user.
void enterRents(int* rents, int num) {
cout << "Enter rents: " << endl;
for (int k = 0; k < 7; k++)
cin >> rents[k];
}

//Display the rents.
void displayRents(int* rents, int n) {
cout << "The rents are" << endl;
for (int k = 0; k < 7; k++)
cout << rents[k] << endl;
}

//Sort the rent amounts from low to high.
void selectionSort (int* rents, int num) {
for (int i = 0; i < num; i++) {
int ind = i;
for (int r = i + 1; r < num; r++) {
if (rents[r] < rents[ind]) {
ind = r;
}
}

//Sum the rents.
void sumRents(int* rents, int sum); {
int n = 6;
cout << " Total Rents " << endl;

for (int k = 0; k < n; k++)
{
sum = sum +rents[k];
}

cout << sum << endl;

}

//Display the rent array memory location.
void displayMemoryLocations(int* rents, int num); {
cout << "Addresses are " << endl;
for (int k = 0; k < 7; k++)
cout << (&rents[k]) << endl;
}

int main() {
int total_properties = 6;
int rents[6];
int sum = 0;

while (true) {

switch (getMenuItem()) {

case 1:
enterRents(rents, total_properties);
break;

case 2:
displayRents(rents, total_properties);
break;

case 3:
selectionSort(rents, total_properties);
break;

case 4:
sumRents(rents, sum);
break;

case 5:
displayMemoryLocations(rents, total_properties);
break;

case 6:
exit(0);
default: cout << "Press any key to continue." << endl;

}
}

}
When you are declaring a function, you put the semi-colon after the parameter list:

int someFunction(int some parameter);

When you are defining a function (i.e. writing the actual function code), you do NOT put a semi-colon after the parameter list:

1
2
3
4
int someFunction(int some parameter)  // NO SEMI-COLON HERE
{
  // code
}
When I start removing the semi-colon, the total of errors goes up. Not sure what I'm doing wrong.
That jsut means that there were lots of errors beforehand, but the incorrect semi-colon prevented the compiler from finding them. Fixing 1 error can sometimes lead to many others. That's OK. Sometimes fixing 1 will solve many.

Get started fixing the errors--start with the beginning of the list and work your way down. After you have fixed a bunch, try compiling again. Pretty quickly you will start reducing the number of errors, and eventually you will have a clean build and you can start debugging your code.
Registered users can post here. Sign in or register to post.