error expected primary-expression before 'else'

I still cannot figure out what I am doing wrong. someone commented on it earlier and I did what they said but I am still getting an error. PLEASE CAN ANYONE HELP!!

error: expected primary-expression before 'else'

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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

// Items for sale:
// Gizmos - Product number 0-999
// Widgets - Product number 1000-1999
// doohickeys - Product number 2000-2999
// thingamajigs - Product number 3000-3999
// Product number >3999 = Invalid Item

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

float ProdNumb; // Product Number

double PrG; // Product Number for Gizmo
double NG; // Number of items
double PG; // Price of Item

double PrW; // Product Number for Widgets
double NW; // Number of items
double PW; // Price of Item


double PrD; // Product Number for Doohickeys
double ND ; // Number of items
double PD ; // Price of Item


double PrT; // Product Number for Thingamajigs
double NT; // Number of items
double PT; // Price of Item


double PrI; //Product Number for Invalid (> 3999)
double NI; // Number of items
double PI; // Price of Item

double total = 0;

int main ()

{

cout << "Enter the product number of the item sold: ";
cin >> ProdNumb;

while (ProdNumb != -1)
{
if (ProdNumb >= 0 && ProdNumb <= 999)
{
	ProdNumb == PrG;
cout << "Enter the number of items sold: ";
cin >> NG;
cout << "Enter the price of one of the items sold: ";
cin >> PG;
}
cout << "Enter the product number of the item sold: ";
cin >> ProdNumb;

else (ProdNumb >= 1000 && ProdNumb <= 1999)
{
	ProdNumb == PrW;
cout << "Enter the number of items sold: ";
cin >> NW;
cout << "Enter the price of one of the items sold: ";
cin >> PW;	   


cout << "Enter the product number of the item sold: ";
cin >> ProdNumb;
}

else (ProdNumb >= 2000 && ProdNumb <= 2999)
{
	ProdNumb == PrD;
cout << "Enter the number of items sold: ";
cin >> ND;
cout << "Enter the price of one of the items sold: ";
cin >> PD;	   

cout << "Enter the product number of the item sold: ";
cin >> ProdNumb;
}

else (ProdNumb >= 3000 && ProdNumb <= 3999)
{
	ProdNumb == PrT;
cout << "Enter the number of items sold: ";
cin >> NT;
cout << "Enter the price of one of the items sold: ";
cin >> PT;


cout << "Enter the product number of the item sold: ";
cin >> ProdNumb;
}

else (ProdNumb <= -2 && ProdNumb == 0 && ProdNumb >= 4000)
{
	ProdNumb == PrI;
cout << "Enter the number of items sold: ";
cin >> NI;
cout << "Enter the price of one of the items sold: ";
cin >> PI;
				


cout << "Enter the product number of the item sold: ";
cin >> ProdNumb;
}
}

cout << "***** Product Sales Summary *****";
cout << "\n";
cout << "\n";

cout << "Gizmo Count: ";
total += NG;
cout << NG;
cout << "\n";
cout << "Gizmo Sales Total: ";
cout << (NG)*(PG);
cout << "\n";
cout << "\n";

cout << "Widget Count: ";
total += NW;
cout << NW;
cout << "\n";
cout << "Widget Sales Total: ";
cout << (NW)*(PW);
cout << "\n";
cout << "\n";

cout << "Dookickey Count: ";
total += ND;
cout << ND;
cout << "\n";
cout << "Doohickey Sales Total: ";
cout << (ND)*(PD);
cout << "\n";
cout << "\n";

cout << "Thingamajig Count: ";
total += NT;
cout << NT;
cout << "\n";
cout << "Thingamajig Sales Total: ";
cout << (NT)*(PT);
cout << "\n";
cout << "\n";

cout << "Invalid Sales: ";
total += NI;
cout << NI;

return 0;
}


it is suppose to have the output:



Enter the product number of the item sold: 1250
Enter the number of items sold: 3
Enter the price for one of the items: 19.99

Enter the product number of the item sold: 2820
Enter the number of items sold: 5
Enter the price for one of the items: 12.50

Enter the product number of the item sold: 3124
Enter the number of items sold: 7
Enter the price for one of the items: 20.30

Enter the product number of the item sold: 987
Enter the number of items sold: 2
Enter the price for one of the items: 10.11

Enter the product number of the item sold: 123
Enter the number of items sold: 36
Enter the price for one of the items: 1.50

Enter the product number of the item sold: 4567
Enter the number of items sold: 9
Enter the price for one of the items: 4.56

Enter the product number of the item sold: 1433
Enter the number of items sold: 20
Enter the price for one of the items: 4.50

Enter the product number of the item sold: 3748
Enter the number of items sold: 1
Enter the price for one of the items: 1.99

Enter the product number of the item sold: 3967
Enter the number of items sold: 5
Enter the price for one of the items: 7.10

Enter the product number of the item sold: 1130
Enter the number of items sold: 30
Enter the price for one of the items: 19.77

Enter the product number of the item sold: 303
Enter the number of items sold: 7
Enter the price for one of the items: 2.00

Enter the product number of the item sold: 530
Enter the number of items sold: 65
Enter the price for one of the items: 0.80

Enter the product number of the item sold: 916
Enter the number of items sold: 130
Enter the price for one of the items: 1.23

Enter the product number of the item sold: 1111
Enter the number of items sold: 75
Enter the price for one of the items: 1.72

Enter the product number of the item sold: 2222
Enter the number of items sold: 7
Enter the price for one of the items: 9.46

Enter the product number of the item sold: 3333
Enter the number of items sold: 4
Enter the price for one of the items: 24.00

Enter the product number of the item sold: 999
Enter the number of items sold: 31
Enter the price for one of the items: 0.90

Enter the product number of the item sold: 7531
Enter the number of items sold: 17
Enter the price for one of the items: 4.10

Enter the product number of the item sold: -1



***** Product Sales Summary *****

Gizmo Count: 271
Gizmo Sales Total: 328.02

Widget Count: 128
Widget Sales Total: 872.07

Doohickey Count: 12
Doohickey Sales Total: 128.72

Thingamajig Count: 17
Thingamajig Sales Total: 275.59

Invalid Sales: 2



THANKS IN ADVANCE FOR ALL THE HELP!!!
Go to the line in your file that the compiler is flagging error on. Start looking for odd things immediately before it. Like a missing } for instance.

Also, learn to indent your code. It makes spotting such things easier.
iHutch105 said you must not do this. That is, you must not have any statements between the closing bracket of the if block and the else.

1
2
3
4
5
6
7
8
9
10
if (condition)
{
   // do stuff
}
// do more stuff here
// and even more stuff
else
{
   // do else stuff
}


You have done this somewhere.

You also changed all your else if to else. I think you should change them back.
Right after your first if, you have statements.

you cannot have if, else, else. You need if, else if, else.

Just to reiterate what vin said.
wow I see it now. THANKS GUYS!!! now the only problem I have is the total issue. I need to sum up all the totals of each ptoduct. then I need the total cost to be multiplied by the cost of each item. I thought I did it right but it doesnt add at all. Ive spent all day staring at this program and I didn't even notice that simple error earlier so Im sure this one is staring me in the face too but I just can't see it. THANKS GUYS FOR ALL THE HELP!!!!!
Last edited on
Topic archived. No new replies allowed.