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
|
#include <iostream>
#include <cmath>
using namespace std;
// Declaring functions outside of int main
double getInput (char);
void showResults(double , double , double,double,double,double );
double calcMarkUp (double , double );
double calcSalesTax (double , double , double );
double calcRetailPrice(double , double ,
double );
int main()
{
cout<<"Rebecca Carolina Katz, Lab8\n";
//variable declarations
double wholesale_price;
double sales_tax_rate;
double mark_up_rate;
double Mark_Up_Amount;
double Sales_Tax_Amount;
double Retail_Price;
char run_the_program_again;
do
{
//get input
wholesale_price=getInput('W');
//cout<<wholesale_price;
sales_tax_rate=getInput('S');
//cout<<sales_tax_rate;
mark_up_rate=getInput('M');
//cout<<mark_up_rate;
Mark_Up_Amount = calcMarkUp(wholesale_price, mark_up_rate ) ;
Sales_Tax_Amount = calcSalesTax(wholesale_price, Mark_Up_Amount, sales_tax_rate);
Retail_Price = calcRetailPrice(wholesale_price, Mark_Up_Amount, Sales_Tax_Amount);
showResults( wholesale_price, mark_up_rate, sales_tax_rate, Mark_Up_Amount, Sales_Tax_Amount, Retail_Price);
cout << "Do you want to run this program again? y or n\n";
cin >> run_the_program_again;
} while (run_the_program_again =='y' || run_the_program_again =='Y' );
cout << "\nGOODBYE\n";
}
void showResults(double wholesale_price, double mark_up_rate, double sales_tax_rate,double Mark_Up_Amount,double Sales_Tax_Amount, double Retail_Price)
{
cout << "Inside Show Results\n\n";
cout << "WholeSale Price : " ;
cout << wholesale_price << endl;
cout << "\n\nMark Up Rate : ";
cout << mark_up_rate << endl;
cout << "\n\nSales Tax Rate : ";
cout << sales_tax_rate << endl;
cout << "\n\nMark Up Amount\n" ;
cout << Mark_Up_Amount << endl;
cout << "\n\nSales Tax Amount\n" ;
cout << Sales_Tax_Amount << endl;
cout << "\n\nRetail Price Amount\n" ;
cout << Retail_Price << endl;
}// end of show result
// This function is taking one parameter that identifies whether the value
// the user is entering is the wholesale price or a percentage to return a real number
double getInput( char variablename)
{
double varvalue;
if( variablename=='W')
{
cout<<"Enter Wholesale Price:";
cin>> varvalue;
while (varvalue<=0)
{
cout<<"Invalid. Wholesale Cost must be a positive number"<<endl;
cout<<"Enter Wholesale Price:";
cin>>varvalue;
}
}
else
{
cout<< "Enter Percentage:";
cin>>varvalue;
while( varvalue<=0|| varvalue >100)
{
cout<<"Invalid. Percentage must be a positive number and < or = 100" <<endl;
cout<< "Enter Percentage:";
cin>> varvalue;
}
}
return varvalue;
}
// This function is calculating the mark up amount.
double calcMarkUp (double wholesale_price, double mark_up_rate)
{
//Variable declarations
double Mark_Up_Amount;
cout << "\n\nInside calcMarkUp\n\n";
Mark_Up_Amount=wholesale_price*(mark_up_rate/100);
return Mark_Up_Amount;
}
// This function is calculating the sales tax amount
double calcSalesTax (double wholesale_price, double Mark_Up_Amount, double sales_tax_rate)
{
//Variable declarations
double Sales_Tax_Amount;
cout << "\n\nInside calcSalesTax\n\n";
Sales_Tax_Amount=(wholesale_price+Mark_Up_Amount)*(sales_tax_rate/100);
return Sales_Tax_Amount;
}
// This function is calculating the retail price
double calcRetailPrice(double wholesale_price, double Mark_Up_Amount,
double Sales_Tax_Amount)
{
//Variable declarations
double Retail_Price;
cout << "\n\nInside calcRetailPrice\n\n";
Retail_Price=(wholesale_price+Mark_Up_Amount+Sales_Tax_Amount);
return Retail_Price;
}
|