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;
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.