Ask your own question, for FREE!
Computer Science 16 Online
OpenStudy (kikuo):

Alright, so I'm on my last program, and I've set it up so there is no syntax errors. Though, there seems to be a few logic errors. When I execute it, I get these crazy numbers.

OpenStudy (kikuo):

//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 calculateCountySalesTax(stateTax, monthlySales); 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 &monthlySales, double &countyTax) { countyTax = monthlySales * COUNTY_SALES_TAX; }//end calculateCountySalesTax void calculateStateSalesTax(double &monthlySales, double &stateTax) { stateTax = monthlySales * STATE_SALES_TAX_RATE; }//end calculateStateSalesTax

OpenStudy (kikuo):

@Sachintha

OpenStudy (kikuo):

State sales tax = monthly sales * 0.04 County sales tax = monthly sales + 0.02 Add these 2 to get total sales tax. Used this from someone in the math section.

OpenStudy (kikuo):

I fixed void calculateCountySalesTax(double &monthlySales, double &countyTax) { countyTax = monthlySales + COUNTY_SALES_TAX; }//end calculateCountySalesTax But I'm still getting odd numbers

OpenStudy (sachintha):

void calculateCountySalesTax(double &countyTaxmonthlySales, double &monthlySales) { countyTax = monthlySales + COUNTY_SALES_TAX; }//end calculateCountySalesTax

OpenStudy (kikuo):

What's different?

OpenStudy (kikuo):

http://prntscr.com/bfu3w6 How does this look ? @Sachintha

OpenStudy (sachintha):

This one works perfectly. //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

OpenStudy (sachintha):

I have marked in red the mistake you have done. You have repeated the same function and has changed the order of parameters. //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 \(\sf\color{red}{calculateCountySalesTax(stateTax, monthlySales);}\) 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 &monthlySales, double &countyTax) { countyTax = monthlySales * COUNTY_SALES_TAX; }//end calculateCountySalesTax void calculateStateSalesTax(double &monthlySales, double &stateTax) { stateTax = monthlySales * STATE_SALES_TAX_RATE; }//end calculateStateSalesTax

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!