Help with execution
Jun 14, 2016 at 3:07am UTC
The final product is pretty big when I run it. I think something is wrong. Any help?
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
//Ashton Dreiling
//Monthly sales tax exercise
#include <iostream>
#include <stdlib.h>
using namespace std;
//module prototypes
void calculateCountySalesTax(double &countyTax, double &monthySales);
void calculateStateSalesTax(double &monthlySales, double &stateTax);
//global constants to help with mathematical expressions
const double STATE_SALES_TAX_RATE = 4;
const double COUNTY_SALES_TAX = 0.2;
int main()
{ //some variables
double monthlySales;
double countyTax;
double stateTax;
double totalSalesTax;
cout << "Today we are going to be calculating your total sales tax." << endl;
cout << "Please enter your total monthly sales." << endl;
cin >> monthlySales;
cout << "You put that your monthly sales are " << monthlySales << endl;
cout << "We will now calculate your county sales tax." << endl;
//moving to module calculateCountySalesTax
calculateCountySalesTax(countyTax, monthlySales);
cout << "Your county sales tax is $" << countyTax << endl;
cout << "We will now calculate your state sales tax." << endl ;
//moving to module calculateStateSalesTax
calculateStateSalesTax(monthlySales, stateTax);
cout << "Your state sales tax is $" << stateTax << endl;
cout << "Now, give us a minute to calculate your total." << endl;
//total sales tax
totalSalesTax = stateTax + countyTax;
cout << "Your total sales tax is $" << totalSalesTax << endl;
system("Pause" );
return 0;
}//end main
void calculateCountySalesTax(double &countyTax, double &monthlySales)
{
countyTax = monthlySales + COUNTY_SALES_TAX;
}//end calculateCountySalesTax
void calculateStateSalesTax(double &monthlySales, double &stateTax)
{
stateTax = monthlySales * STATE_SALES_TAX_RATE;
}//end calculateStateSalesTax
Last edited on Jun 14, 2016 at 3:13am UTC
Jun 14, 2016 at 3:46am UTC
I would change your function prototypes from:
1 2
void calculateCountySalesTax(double &countyTax, double &monthySales);
void calculateStateSalesTax(double &monthlySales, double &stateTax);
To:
1 2 3
//The monthly Sales should not change after the user determines the value.
void calculateCountySalesTax(double &countyTax, const double monthySales);
void calculateStateSalesTax(const double monthlySales, double &stateTax);
The final product is pretty big when I run it.
What do you mean by it? What values do you input and what is the output?
I am not able to compile your code (work computer disable the ability for it), but I use a scratch of paper to practice the following value:
monthlySales = 40;
countyTax = 40 + 4 = 44
stateTax = 40 * 0.2 = 8
totalSalesTax = 52
My calculations were wrong. Disregard it
Last edited on Jun 14, 2016 at 4:05am UTC
Jun 14, 2016 at 3:57am UTC
http://prntscr.com/bg3p48
Here you go. : )
The values seem weird. Are they correct? If not, what did I do wrong?
Also, if I changed that to const double monthlySales what else would I have to change in my code?
Last edited on Jun 14, 2016 at 3:59am UTC
Jun 14, 2016 at 4:10am UTC
Based on your code on how to determine the taxes My calculation with a scratch paper are as follows:
monthlySales = 125;
countyTax = monthlySales + COUNTY_SALES_TAX;
countyTax = 125 + .2 = 125.2
stateTax = monthlySales * STATE_SALES_TAX_RATE;
stateTax = 125 * 4 = 500
totalSalesTax = stateTax + countyTax;
totalSalesTax = 500 + 125.2 = 625.2
It matches with your program.
Also, if I changed that to const double monthlySales what else would I have to change in my code?
1 2 3 4 5 6 7 8 9
void calculateCountySalesTax(double &countyTax, const double monthlySales)
{
countyTax = monthlySales + COUNTY_SALES_TAX;
}//end calculateCountySalesTax
void calculateStateSalesTax(const double monthlySales, double &stateTax)
{
stateTax = monthlySales * STATE_SALES_TAX_RATE;
}//end calculateStateSalesTax
Jun 14, 2016 at 4:23am UTC
I already submitted it. Will the fact it's not a const affect anything?
Jun 14, 2016 at 4:29am UTC
For this small program. It should be fine. It is more about building the habit so when you begin to start writing larger programs.
Jun 14, 2016 at 5:40am UTC
Thanks for the advice!
Topic archived. No new replies allowed.