array function with structures

I'm trying to figure out how to do a second part to an assignment that was finished. The idea is that we are supposed to change the functions/prototypes into the format of a structure. I'm having trouble understanding how to create a function that could be used in the main by utilizing this structure format. The problem may be that it is an array which is causing some issue that I can't pin down. If someone could offer some advice I'd be quite happy.

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
#include <iostream>
#include <string>
#include <iomanip>
using namespace std; 

struct DIV {
        float sale;
        string name;
};

// Function Prototypes
void populate_div_sales(DIV [], int);   // this function populates an array wit$
int findHighest (DIV [], int);         // this function will now return the ind$
void print_result(DIV [], int); // displays result based on the index of highes$

int main() {
        int top_div_index = 0;  // will be assigned the index of the top divisi$
        DIV div_info[4];        // array of type DIV holding the divisions' str$

        div_info[0].name = "Northeast";
        div_info[1].name = "Southeast";
        div_info[2].name = "Northwest";
        div_info[3].name = "Southwest";

        //keep debug printout
        cout << "debug print for array div_info" << endl;
                for (int i=0; i<4; i++) {
                cout << div_info[i].name << endl;
        }
        // populate div_sales
        populate_div_sales(div_info, 4);

        //debug printout
        cout << "debug print for array div_info" << endl;
        for (int i=0; i<4; i++) {
                cout << div_info[i].sale << endl;
        }

        // find the highest region and save it to this index
//      top_div_index = findHighest(div_sales, 4);

        return 0;
}

void populate_div_sales(DIV f_div_info[], int f_size) {
//      float f_sales[4];
//      string f_name[4];

        // loop to input quarterly sales
        for (int i=0; i<f_size; i++) {
                cout << "Enter sales of " << f_div_info[i] << "division: $";

                cin >> f_div_info[i];
        }
}
What is your exact problem?
Can you post your assignment?
~deleted assignment link
1
2
3
4
5
6
7
8
void populate_div_sales(DIV div_info[], int size) {
        // loop to input quarterly sales
        for (int i=0; i<size; i++) {
                cout << "Enter sales of " << div_info.name[i] << "division: $";
                cin >> div_info.sale[i];
        }
}


I keep having a format error around here, I can't assign the div_info[] the proper numbers. Oh, I just need to fix it so it's div_info[i].name.

Finished the program, thanks for the help!
Last edited on
Topic archived. No new replies allowed.