Errors in my program

I'm trying to create a program similar to a cash register that will calculate the total of the items as well as print the receipt. However, when I build it, it gives me two warnings and an error:
(1) warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header

(2) warning C4627: '#include <stdio.h>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header

(3) fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

I don't understand what it is saying. Can I please have help in removing these errors to allow my program to run smoothly.

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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
  #include <iostream>
#include <stdio.h>


int main ()
{
	using namespace std;
  cout << "Welcome to SM Supermarket!\n";
  int code = 0;
  cout << "Please enter the barcode of you first item\n";

  
  cin >> code;

  int amount = 0;
  cout << "How many do you want to purchase?\n";

  
  cin >> amount;

  string product[10];
  product[0] = "Hagen Daaz Macadamia Nut Ice Cream";
  product[1] = "Bounty Tissue";
  product[2] = "Chips Ahoy Cookies";
  product[3] = "Tide Laundry Detergent";
  product[4] = "Lays Original Chips";
  product[5] = "Sunny D Orange Juice";
  product[6] = "Organic Bananas";
  product[7] = "Oreo Cookies";
  product[8] = "Red Delicious Apples";
  product[9] = "Extra Cheesy Kraft Dinner";

  int priceA = 0, priceB = 0, priceC = 0, priceD = 0, priceE = 0, priceF = 0, priceG = 0, priceH = 0, priceI = 0, priceJ = 0;

  while (code != 0000){

	  if (code == 0123){
	 int priceA = 7 * amount;
  printf("%s\n",product[0].c_str());
	  }

  else if (code == 0124){
	 int priceB = 10 * amount;
  printf("%s\n",product[1].c_str());
  }
  
  else if (code == 0125){
	 int priceC = 3 * amount;
  printf("%s\n",product[2].c_str());
  }

  else if (code == 0126){
	 int priceD = 6 * amount;
  printf("%s\n",product[3].c_str());
  }
  
  else if (code == 0127){
	 int priceE = 2 * amount;
  printf("%s\n",product[4].c_str());
  }
  
  else if (code == 0133){
	 int priceF = 3 * amount;
  printf("%s\n",product[5].c_str());
  }

  else if (code == 0134){
	 int priceG = 5 * amount;
  printf("%s\n",product[6].c_str());
  }
  
  else if (code == 0130){
	 int priceH = 2 * amount;
  printf("%s\n",product[7].c_str());
  }

  else if (code == 0131){
	 int priceI = 3 * amount;
  printf("%s\n",product[8].c_str());
  }

  else if (code == 0132){
	 int priceJ = 4 * amount;
  printf("%s\n",product[9].c_str());
  }
  } 
  
  cout << "Please enter your coupon code, if you do not have any, please press '0'\n";

  int coupon = 0;
  
  cin >> coupon;
  
  if (coupon == 051){
	  cout << "50% discount of 'Bounty Tissue'\n";
	  
	   priceB = priceB / 2;
  }
  else if (coupon == 017){
	  cout << "$2 off any Hagen Daaz product\n";

	   priceA = priceA - 2;
  }
  else if (coupon == 046){
	  cout << "$1 off two Lays original Chips\n";

	   priceE = priceE * 2 - 1;
  }
  else if (coupon == 035){
	  cout << "$1 off any Sunny D product\n";

	  priceF = priceF - 1;
  }
  
  else if (coupon == 0){
	  cout << "Your purchase is being processed\n";
  }
  
  int bags = 0; 
  cout << "How many bags would you like to purchase(1 bag/$1 each)?\n";

  cin >> bags;

  bags = bags * 1;


  int subtotal = priceA + priceB + priceC + priceD + priceE + priceF + priceG + priceH + priceI + priceJ + bags;
  cout << "Subtotal:\n\n " << subtotal;
  double total = subtotal * 1.1;
  cout << "Total:\n\n " << total;

  cout << "Would you like to pay with debit or cash? Press '1' for debit and '2' for cash\n";
  
  int payment = 0;
  int pin = 0;
  double change = 0;
  double cash = 0;

	  if (payment == 1){
		  cout << "Enter your pin number: ";
		  cin >> pin;
		  cout << "Approved. Your purchase is processing...\n";
	  }
	  else if (payment == 2){
		  cout << "Please enter the amount you are paying with:\n";
		  cin >> cash;
		  change = cash - total;
	  }

  cout << "Thank you for your purchase. Your reciept is printing...\n";
  cout << "<<<<<<<<<<<<<<<<<<<<<SM Supermarket>>>>>>>>>>>>>>>>>>>>>\n";
  cout << " Cashier: Samantha & Madeleine\n";
  cout << "\n";
  cout << "\n";
  cout << "--------------------------------------------------------\n";
  printf("%s\n",product[0].c_str());
  cout << "$" << priceA;
  printf("%s\n",product[1].c_str());
  cout << "$" << priceB;
  printf("%s\n",product[2].c_str());
  cout << "$" << priceC ;
  printf("%s\n",product[3].c_str());
  cout << "$" << priceD;
  printf("%s\n",product[4].c_str());
  cout << "$" << priceE;
  printf("%s\n",product[5].c_str());
  cout << "$" << priceF;
  printf("%s\n",product[6].c_str());
  cout << "$" << priceG;
  printf("%s\n",product[7].c_str());
  cout << "$" << priceH;
  printf("%s\n",product[8].c_str());
  cout << "$" << priceI;
  printf("%s\n",product[9].c_str());
  cout << "$" << priceJ;
  cout << "\n";
  cout << "Bags";
  cout << "$" << bags;
  cout << "\n";
  cout << "-----------------";
  cout << "Subtotal: " << subtotal;
  cout << "Total: " << total;
  cout << "Amount Given: " << cash;
  cout << "Change: " << change;
  cout << "-----------------";
  cout << "Thanks for shopping at SM Supermarket!";
  cout << "***************************************";


  return 0;
}
try adding #include "stdafx.h" to your program
Last edited on
when i do so, it gives me 102 errors.
what compiler are you using?
and what kind of project is it? for example is it a console application or an empty project?
Statement

#include "stdafx.h"

must be before all other #include(s).
@Yanson: I'm using visual c++ 2008. and im not sure about the project as im new to c++

@Vlad: I tried what you said and i now have less errors, however i still have 26 errors regarding the variables priceA, priceB, priceC etc. when calculating the coupon price as well as when assigning their sum to the subtotal variable.


Do you see anything I can fix?

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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include "stdafx.h"
#include <iostream>
#include <stdio.h>



int main ()
{
	using namespace std;


  cout << "Welcome to SM Supermarket!\n";
  int code = 0;

  string product[10];
  product[0] = "Hagen Daaz Macadamia Nut Ice Cream";
  product[1] = "Bounty Tissue";
  product[2] = "Chips Ahoy Cookies";
  product[3] = "Tide Laundry Detergent";
  product[4] = "Lays Original Chips";
  product[5] = "Sunny D Orange Juice";
  product[6] = "Organic Bananas";
  product[7] = "Oreo Cookies";
  product[8] = "Red Delicious Apples";
  product[9] = "Extra Cheesy Kraft Dinner";
  
  while (code != 000){
  cout << "Please enter the barcode of your item\n";

  
  cin >> code;

  int amount = 0;
  cout << "How many do you want to purchase?\n";

  
  cin >> amount;

  

  int priceA = 0, priceB = 0, priceC = 0, priceD = 0, priceE = 0, priceF = 0, priceG = 0, priceH = 0, priceI = 0, priceJ = 0;

  

	  if (code == 0123){
	  priceA = 7 * amount;
  printf("%s\n",product[0].c_str());
	  }

  else if (code == 0124){
	  priceB = 10 * amount;
  printf("%s\n",product[1].c_str());
  }
  
  else if (code == 0125){
	  priceC = 3 * amount;
  printf("%s\n",product[2].c_str());
  }

  else if (code == 0126){
	  priceD = 6 * amount;
  printf("%s\n",product[3].c_str());
  }
  
  else if (code == 0127){
	  priceE = 2 * amount;
  printf("%s\n",product[4].c_str());
  }
  
  else if (code == 0133){
	  priceF = 3 * amount;
  printf("%s\n",product[5].c_str());
  }

  else if (code == 0134){
	  priceG = 5 * amount;
  printf("%s\n",product[6].c_str());
  }
  
  else if (code == 0130){
	 priceH = 2 * amount;
  printf("%s\n",product[7].c_str());
  }

  else if (code == 0131){
	  priceI = 3 * amount;
  printf("%s\n",product[8].c_str());
  }

  else if (code == 0132){
	 priceJ = 4 * amount;
  printf("%s\n",product[9].c_str());
  }
  } 
  
  cout << "Please enter your coupon code, if you do not have any, please press '0'\n";

  int coupon = 0;
  
  
  cin >> coupon;
  
  if (coupon == 051){
	  cout << "50% discount of 'Bounty Tissue'\n";
	  
	   priceB = priceB / 2;
  }
  else if (coupon == 017){
	  cout << "$2 off any Hagen Daaz product\n";

	   priceA = priceA - 2;
  }
  else if (coupon == 046){
	  cout << "$1 off two Lays original Chips\n";

	   priceE = priceE * 2 - 1;
  }
  else if (coupon == 035){
	  cout << "$1 off any Sunny D product\n";

	  priceF = priceF - 1;
  }
  
  else if (coupon == 0){
	  cout << "Your purchase is being processed\n";
  }
  
  int bags = 0; 
  cout << "How many bags would you like to purchase(1 bag/$1 each)?\n";

  cin >> bags;

  bags = bags * 1;


  int subtotal = priceA + priceB + priceC + priceD + priceE + priceF + priceG + priceH + priceI + priceJ + bags;
  cout << "Subtotal:\n\n " << subtotal;
  double total = subtotal * 1.1;
  cout << "Total:\n\n " << total;

  cout << "Would you like to pay with debit or cash? Press '1' for debit and '2' for cash\n";
  
  int payment = 0;
  int pin = 0;
  double change = 0;
  double cash = 0;

	  if (payment == 1){
		  cout << "Enter your pin number: ";
		  cin >> pin;
		  cout << "Approved. Your purchase is processing...\n";
	  }
	  else if (payment == 2){
		  cout << "Please enter the amount you are paying with:\n";
		  cin >> cash;
		  change = cash - total;
	  }

  cout << "Thank you for your purchase. Your reciept is printing...\n";
  cout << "<<<<<<<<<<<<<<<<<<<<<SM Supermarket>>>>>>>>>>>>>>>>>>>>>\n";
  cout << " Cashier: Samantha & Madeleine\n";
  cout << "\n";
  cout << "\n";
  cout << "--------------------------------------------------------\n";
  printf("%s\n",product[0].c_str());
  cout << "$" << priceA;
  printf("%s\n",product[1].c_str());
  cout << "$" << priceB;
  printf("%s\n",product[2].c_str());
  cout << "$" << priceC ;
  printf("%s\n",product[3].c_str());
  cout << "$" << priceD;
  printf("%s\n",product[4].c_str());
  cout << "$" << priceE;
  printf("%s\n",product[5].c_str());
  cout << "$" << priceF;
  printf("%s\n",product[6].c_str());
  cout << "$" << priceG;
  printf("%s\n",product[7].c_str());
  cout << "$" << priceH;
  printf("%s\n",product[8].c_str());
  cout << "$" << priceI;
  printf("%s\n",product[9].c_str());
  cout << "$" << priceJ;
  cout << "\n";
  cout << "Bags";
  cout << "$" << bags;
  cout << "\n";
  cout << "-----------------";
  cout << "Subtotal: " << subtotal;
  cout << "Total: " << total;
  cout << "Amount Given: " << cash;
  cout << "Change: " << change;
  cout << "-----------------";
  cout << "Thanks for shopping at SM Supermarket!";
  cout << "***************************************";


  return 0;
  }
You should show what are the error messages.
I've just fixed it and I have no more errors. Thanks everyone for the help! I just have a problem. When i execute my program, the prices do not seem to display nor add up on the receipt. Is it because my priceA, priceB, etc. and the calculations of the prices are inside if statements? If so, how can i fix this?

This is what I currently have
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include "stdafx.h"
#include <iostream>
#include <stdio.h>



int main ()
{
	using namespace std;


  cout << "Welcome to SM Supermarket!\n";
  int code = 0;

  string product[10];
  product[0] = "Hagen Daaz";
  product[1] = "Bounty Tissue";
  product[2] = "Chips Ahoy Cookies";
  product[3] = "Tide Laundry Detergent";
  product[4] = "Lays Original Chips";
  product[5] = "Sunny D Orange Juice";
  product[6] = "Organic Bananas";
  product[7] = "Oreo Cookies";
  product[8] = "Red Delicious Apples";
  product[9] = "Extra Cheesy Kraft Dinner";

   int priceA = 0, priceB = 0, priceC = 0, priceD = 0, priceE = 0, priceF = 0, priceG = 0, priceH = 0, priceI = 0, priceJ = 0;
  
 // while (code != 000){
  cout << "Please enter the barcode of your item\n";

  
  cin >> code;

  int amount = 0;
  cout << "How many do you want to purchase?\n";

  
  cin >> amount;

  

	  if (code == 0123){
	  priceA = 7 * amount;
     printf("%s\n",product[0].c_str());
	  }

  else if (code == 0124){
	  priceB = 10 * amount;
  printf("%s\n",product[1].c_str());
  }
  
  else if (code == 0125){
	  priceC = 3 * amount;
  printf("%s\n",product[2].c_str());
  }

  else if (code == 0126){
	  priceD = 6 * amount;
  printf("%s\n",product[3].c_str());
  }
  
  else if (code == 0127){
	  priceE = 2 * amount;
  printf("%s\n",product[4].c_str());
  }
  
  else if (code == 0133){
	  priceF = 3 * amount;
  printf("%s\n",product[5].c_str());
  }

  else if (code == 0134){
	  priceG = 5 * amount;
  printf("%s\n",product[6].c_str());
  }
  
  else if (code == 0130){
	 priceH = 2 * amount;
  printf("%s\n",product[7].c_str());
  }

  else if (code == 0131){
	  priceI = 3 * amount;
  printf("%s\n",product[8].c_str());
  }

  else if (code == 0132){
	 priceJ = 4 * amount;
  printf("%s\n",product[9].c_str());
  }
  //} 
  
  int coupon = 0;
  //while (coupon != 000){
	  cout << "Please enter your coupon code, if you do not have any, please press '0'. Press '000' when finished entering coupon(s)\n";

  
  
  cin >> coupon;

  if (coupon == 051){
	  cout << "50% discount of 'Bounty Tissue'\n";
	  
	   priceB = priceB / 2;
  }
  else if (coupon == 017){
	  cout << "$2 off any Hagen Daaz product\n";

	   priceA = priceA - 2;
  }
  else if (coupon == 046){
	  cout << "$1 off two Lays original Chips\n";

	   priceE = priceE * 2 - 1;
  }
  else if (coupon == 035){
	  cout << "$1 off any Sunny D product\n";

	  priceF = priceF - 1;
  }
  
  else if (coupon == 0){
	  cout << "Your purchase is being processed\n";
  }
  //}
  
  
  int bags = 0; 
  cout << "How many bags would you like to purchase(1 bag/$1 each)?\n";

  cin >> bags;

  bags = bags * 1;


  int subtotal = priceA + priceB + priceC + priceD + priceE + priceF + priceG + priceH + priceI + priceJ + bags;
  cout << "Subtotal:\n\n " << subtotal;
  double total = subtotal * 1.1;
  cout << "Total:\n\n " << total;

  int payment = 0;
  int pin = 0;
  double change = 0;
  double cash = 0;

  cout << "Would you like to pay with debit or cash? Press '1' for debit and '2' for cash\n";

  cin >> payment;
  
 
	  if (payment == 1){
		  cout << "Enter your pin number: ";
		  cin >> pin;
		  cout << "Approved. Your purchase is processing...\n";
	  }
	  else if (payment == 2){
		  cout << "Please enter the amount you are paying with:\n";
		  cin >> cash;
		  change = cash - total;
	  }

  cout << "Thank you for your purchase. Your reciept is printing...\n";
  cout << "<<<<<<<<<<<<<<<<<<<<<SM Supermarket>>>>>>>>>>>>>>>>>>>>>\n";
  cout << " Cashier: Samantha & Madeleine\n";
  cout << "\n";
  cout << "\n";
  cout << "--------------------------------------------------------\n";
  printf("%s\n",product[0].c_str());
  cout << "$" << priceA << "\n";
  printf("%s\n",product[1].c_str());
  cout << "$" << priceB << "\n";
  printf("%s\n",product[2].c_str());
  cout << "$" << priceC << "\n";
  printf("%s\n",product[3].c_str());
  cout << "$" << priceD << "\n";
  printf("%s\n",product[4].c_str());
  cout << "$" << priceE << "\n";
  printf("%s\n",product[5].c_str());
  cout << "$" << priceF << "\n";
  printf("%s\n",product[6].c_str());
  cout << "$" << priceG << "\n";
  printf("%s\n",product[7].c_str());
  cout << "$" << priceH << "\n" ;
  printf("%s\n",product[8].c_str());
  cout << "$" << priceI << "\n";
  printf("%s\n",product[9].c_str());
  cout << "$" << priceJ << "\n";
  cout << "\n";
  cout << "Bags";
  cout << "$" << bags;
  cout << "\n";
  cout << "-----------------";
  cout << "Subtotal: " << subtotal << "\n";
  cout << "Total: " << total << "\n";
  cout << "Amount Given: " << cash << "\n";
  cout << "Change: " << change << "\n";
  cout << "-----------------";
  cout << "Thanks for shopping at SM Supermarket!";
  cout << "***************************************";
  cout << "Please press '1' to exit. Have a nice day!";
  int exit = 0;
  cin >> exit;
  }
Integer literals starting with zero are octal integer literals. So in the statement

if (code == 0123){

you are comparing variable code with value 1 * 8^2 + 2 * 8^1 + 3 * 8^1 that is equal to 83.
Last edited on
thank you so much for your help. I got it to work :)
Topic archived. No new replies allowed.