Debugging Help!! Pointers in Arrays

So My program runs great in Xcode, but when Transferred to Visual Studio it dies(Says it can't find the file to run it.). Can anyone see what's wrong with my code?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126


//Description:/*You are writing an accounting program for a property management company. Use arrays to hold the 5 rental properties’ income. Write a function that accepts as arguments the array of integers and an integer representing the number of elements in the array. Sort the rent from high to low and then output the rents from high to low. In addition, display the memory location of first and last items in the array.*/

#include <iostream>
#include <iomanip>

using namespace std;
//Globals
int SIZE = 5;

//Function Prototypes
void displayMenu();
void sort(int *rentp);
void DisplayAdd(int *rentp);



int main() {

    int rent[SIZE];
   
    int option;
    
    
    cout<<"First please enter the rental income of your 5 properties: \n";
    
    for (int i = 0,count = 1; i < SIZE; i++, count++) {
        
        cout<< "Property "<< count<<":$";
        cin>> rent[i];
        
        
    }
    cout<<endl;
    
    while (true) {
        
        displayMenu();
        cout<<"Please make your selection: ";
        cin>> option;
        cout<<endl;
        
        switch (option) {
            case 1:
                sort(rent);
                cout<<endl;
                break;
                
           case 2:
                DisplayAdd(rent);
                cout<<endl;
                break;
            
                
            default:
                if (option != 1 && option != 2 && option != 3) {
                    cout<<"Invalid input, try again.\n"<<endl;
                }
              
                break;
        }
        
        if (option == 3)
            break;
        }
        
    
    
    cout<<"Thank you, Good-Bye.........\n";
    

    
    system("Pause");
    
    return 0;
}
void displayMenu(){



    cout<<"Menu Of Options: \n";
    cout<<"1.Sort rent High to Low \n";
    cout<<"2.Display the memory location of the first and last items in the array \n";
    cout<<"3.Exit \n";

    
}

void sort(int *rentp){

    int startscan,maxIndex;
    double maxVal;
    for (startscan = 0;startscan < (SIZE -1); startscan++){
        maxIndex = startscan;
        maxVal = rentp[startscan];
        
        for (int index = startscan +1; index < SIZE; index++) {
            if (rentp[index] > maxVal) {
                maxVal = rentp[index];
                maxIndex = index;
            }
        }
        rentp[maxIndex] = rentp[startscan];
        rentp[startscan] = maxVal;
    }
    cout<<"Rental Income Listed from Highest to Lowest: \n";
    for (int i = 0, count = 1; i < SIZE; i++,count++) {
        cout<< fixed <<showpoint <<setprecision(2);
        cout<<"$"<<rentp[i]<<"\n";
        
    }
}

void DisplayAdd(int *rentp){

    cout<<"The memory location of the first item in the array: "<< &rentp[0];
    cout<<endl;

    cout<<"The memory location of the last item in the array:"<< &rentp[4];
    cout<<endl;


}

1
2
int SIZE = 5;
int rent[SIZE];


This is not right, array size has to be constant at compile time, change to const int SIZE = 5;

Edit:

It also works perfectly fine on my system and on cpp.sh - http://www.cpp.sh/42bc
Last edited on
What file do you mean there? The executable?
Tarik,
That was the issue. Thanks!
Topic archived. No new replies allowed.