code doesn't compile

so my code works in shell but doesn't work in pico c++ editor .cpp compiler

these are the errors i get:

top_div_array.cpp:81:71: missing terminating " character
top_div_array.cpp:82:2: missing terminating " character
top_div_array.cpp: In function `void print_result(float*, std::string*, int)':
top_div_array.cpp:82: error: syntax error before string constant
gen242@cs04:~>

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
 //poonam patel
//cs 102 spring
//calculates highest divisions sales using array and prototypes function

//libraries
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
  
//function prototypes
void populate_div_sales(float[], string[], int);
int findHighest (float[], int);
void print_result(float[], string[], int);

int main()
{
int top_div_index = 0;
float div_sales[4];
string div_regions[4];

//arrays for regioons
div_regions[0] = "Northeast";
div_regions[1] = "Southeast";
div_regions[2] = "Northwest";
div_regions[3] = "Southwest";

//function
populate_div_sales(div_sales,div_regions,4);
//debug
cout<<"debug print for array div_sales_array"<<endl;
for (int i=0; i<4; i++)
{
cout<<div_sales[i]<<endl;
}
top_div_index = findHighest(div_sales,4);
cout<<"debug for top_div_index:"<<top_div_index<<endl;

print_result(div_sales, div_regions, 4);

return 0;
}
//division sales
void populate_div_sales(float f_div_sales[], string f_div_regions[], int size)
{
float sale;
cout<<"Enter Division Sales for 4 regions\n";
for(int i=0;i<size; i++)
{
while(true)

cout<<f_div_regions[i]<<":$";
cin>>sale;
if(sale>=0)
{
f_div_sales[i]=sale;
break;
}
else
{
cout<<"sale should be positive integer, please try again...\n";
}
}
}
}
//findinghighest
int findHighest(float sales[], int size)
{
float greatestSalesAmount=0;
int save_index=0;

greatestSalesAmount=sales[0];
for(int i=0; i<size; i++)
{
if(sales[i]>greatestSalesAmount)

{

greatestSalesAmount=sales[i];
save_index=i;
}
}
return save_index;  
}

//printresults
void print_result(float f_sales[], string f_divisions[], int size)
{
int highest=findHighest(f_sales,4);
cout<<fixed<<setprecision(2)<<"Highest sale:"<<f_divisions[highest]<<"division whicch made
$"<<f_sales[highest];
}
You have got one more end brace on line 62-65 than needed. This would have been apparent if you had indented the code properly.

The second problem is on line 90-91. A string literal needs to be on one line. If you want a newline character in the string you need to use '\n'. "division whicch made\n$"
Last edited on
Topic archived. No new replies allowed.