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.
////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
constdouble nike = 15.99;
constdouble adidas = 14.98;
constdouble 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;
}
elseif(adidas == 14.98)
{
final_price = final_price + adidas;
priceToAdd = final_price * tax;
final_price = priceToAdd + final_price;
}
elseif(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;
}
elseif(a == true)
{
cout << "The final price for your Nike shoes is: \n\t$" << final_price << endl;
}
elseif(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...