debug for struct array

I am having problems with debug sections, please help
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
  #include <iostream>
#include <string>
#include <iomanip>
using namespace std;

struct DIV {
float sale;
string name;
} ;

void populate_div_sales(DIV[], int);
int findHighest (DIV[], int);
void print_result(DIV[], int);

//*************************************************
//************ main *******************************
//*************************************************
int main ()
{
int top_div_index;
  
DIV div_info[] = { { 0, "Northeast" }, { 0, "Northwest" }, { 0, "Southwest" }, { 0, "Southeast" } };
  

populate_div_sales(div_info, 4);

//debug
cout<<"debug print for array div_info"<<endl;
for (int i=0;i<4; i++){
    cout<<div_info[i]<<endl;
}
  
top_div_index = findHighest(div_info, 4);
//debug
cout<<"debug for top_div_index"<<top_div_index<<endl;

print_result(div_info, 4);
  
return 0;
}



//************ subroutine definitions below *******************
//*************************************************
//************ populate_div_sales *****************
//*************************************************
// The params for the function definition are given to help get started
// - note the f_ preceding variable names. Use
// this convention to help relate and contrast both the calling and the
// receiving variables.
void populate_div_sales(DIV div_info[], int size)
{
float sale;
cout << "Enter Division Sales for 4 regions\n";
for(int i=0; i<size;i++)
{
while(true)
{
cout <<div_info[i].name<<": $";
cin >> sale;
if(sale >=0)
{
div_info[i].sale = sale;
break;

}
else
{
cout <<"Sale should be positive integer, please try again...\n";
}
  
}
}
}

//*************************************************
//************ findHighest ************************
//*************************************************
int findHighest(DIV div_info[], int size)
{
float greatestSalesAmount = 0;
int save_index = 0;
  
greatestSalesAmount= div_info[0].sale;
for(int i=1; i<size;i++)
{
if(div_info[i].sale>greatestSalesAmount)
{
greatestSalesAmount=div_info[i].sale;
save_index=i;
}
}
  
return save_index;
}
//*************************************************
//************ print_result ***********************
//*************************************************
void print_result(DIV div_info[], int size)
{

int highest=findHighest(div_info,4);


cout <<fixed<<setprecision(2)<< "Highest sale: "<< div_info[highest].name<<" division which made $"<< div_info[highest].sale;
}
Line 30: You cannot print div_info[i] directly. Try something like

cout<< "name: " << div_info[i].name << ", sale: " << div_info[i].sale <<endl;
Topic archived. No new replies allowed.