Code Sales Program

I recently made this program (for learning, ignore the fake data). Is there a way I colud've made this program more efficiently? Btw, tax is supposedly 6% for the state.

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
   ////store-source.cpp calculates a////
  /////sample store's item's price/////
 ///////sale, code number and tax/////
///////Created by Ted - 09/02/2011///

#include <iostream>
#include <iomanip>
#include <string>

using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::setprecision;
using std::fixed;
using std::getline;

int main(){
	/*Declare variables and constants*/
	bool n              = false; //n stands for Nike
	bool a              = false; //A for Adidas
	bool o              = false; //O for OP
	const double nike   = 15.99;
	const double adidas = 14.98;
	const double op     = 12.99;
	double shoe_size    =  1.50;
	int choice          =     0;
	char prompt_1       =   ' ';
	int item_code       =     0;
	string name         =   " ";
	double final_price  =  0.00;
	double tax          =  0.06;
	double priceToAdd   =  0.00;

	/*get user input*/
	cout << "What is the item's code number? " << endl;
	cin >> item_code;
		switch (item_code)
		{
			case 1:
				cout << "You have selected (1) Nike.\nIs this correct? (Y/N) " << endl;
				prompt_1 = islower(prompt_1);
				cin >> prompt_1;
				n = true;
				break;
			case 2:
				cout << "You have selected (2) Adidas.\nIs this correct? (Y/N) " << endl;
				prompt_1 = islower(prompt_1);
				cin >> prompt_1;
				a = true;
				break;
			case 3:
				cout << "You have selected (3) OP.\nIs this correct? (Y/N) " << endl;
				prompt_1 = islower(prompt_1);
				cin >> prompt_1;
				o = true;
				break;
			default:
				cout << "This code number does not exist in our system." << endl;
		}

		if(prompt_1 == 'n'){
		{
			cout << "Please try again.\nRestart this program. " << endl;
		}
		} //end if
		cout << "Now, what's your shoe size? " << endl;
		cin >> choice;
		switch(choice)
		{
		case 0:
			cout << "Invlid - well actually impossible...\n" << endl;
			break;
		case 1:
		case 2:
		case 3:
		case 4:
			final_price = shoe_size * 1;
			break;
		case 5:
		case 6:
		case 7:
		case 8:
			final_price = shoe_size * 2;
			break;
		default:
			final_price = shoe_size * 3;
		}

		//calculate final price
		if(nike == 15.99)
		{
			final_price = final_price + nike;
			priceToAdd = final_price * tax;
			final_price = priceToAdd + final_price;
		}
		else
			if(adidas == 14.98)
			{
			final_price = final_price + adidas;
			priceToAdd = final_price * tax;
			final_price = priceToAdd + final_price;
			}
			else
				if(op == 12.99)
				{
					final_price = final_price + op;
					priceToAdd = final_price * tax;
					final_price = priceToAdd + final_price;
				}

				//display answer
				cout << setprecision(2) << fixed;
				if(n == true)
				{
					cout << "The final price for your Nike shoes is: \n\t$" << final_price << endl;
				}
				else
					if(a == true)
					{
						cout << "The final price for your Nike shoes is: \n\t$" << final_price << endl;
					}
					else
						if(o == true)
						{
							cout << "The final price for your Nike shoes is: \n\t$" << final_price << endl;
						}
						else
							cout << "There was an error processing your request." << endl;
				cout << "Press the ENTER key to continue... " << endl;
				cin.ignore(10, '\n');
				cin.get();
	return 0;
} //end of main function 


This is an example output (for a successful run)

What is the item's code number?
3
You have selected (3) OP.
Is this correct? (Y/N)
y
Now, what's your shoe size?
6
The final price for your Nike shoes is:
        $20.13
Press the ENTER key to continue...
Last edited on
Topic archived. No new replies allowed.