Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How can I get this program I wrote to calculate the sales tax if it is deemed th

ID: 3922051 • Letter: H

Question

How can I get this program I wrote to calculate the sales tax if it is deemed the customer needs to pay sales tax? Whether I put in yes or no, it always give me the answer without applying sales tax.

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
   //declare vairables and constants
   int pounds = 0;
   double poundPrice = 0.0;
   char yesTax = ' ';
   const int doubleTax = 0.035;
   double poundsPrice = 0.0;
   double withTax = 0.0;
   double noTax = 0.0;
   double withTaxA = 0.0;
   double withTaxB = 0.0;

   cout << "Pounds ordered : ";
   cin >> pounds;
   cout << "Price per pound : ";
   cin >> poundPrice;
   cout << "Does the customer need to be charged sales tax? (Y or N) : ";
   cin >> yesTax;

   if (yesTax == 'Y')
   {
       withTaxA = (poundPrice * pounds);
       withTaxB = (withTaxA * doubleTax);
       withTax = (withTaxA + withTaxB);
       cout << fixed << setprecision(2);
       cout << "Total: $" << withTax << endl;
   }
   else if (yesTax != 'Y')
   {
       noTax = poundPrice * pounds;
       cout << fixed << setprecision(2);
       cout << "Total: $" << noTax << endl;
   }
   //end if

   system("PAUSE");
   return 0;
} //end of main function

Explanation / Answer

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
//declare vairables and constants
double pounds = 0;
double poundPrice = 0.0;
char yesTax = ' ';
// tax should be double
const double doubleTax = 0.035;

double poundsPrice = 0.0;
double withTax = 0.0;
double noTax = 0.0;
double withTaxA = 0.0;
double withTaxB = 0.0;
  
cout << "Pounds ordered : ";
cin >> pounds;
cout << "Price per pound : ";
cin >> poundPrice;
cout << "Does the customer need to be charged sales tax? (Y or N) : ";
cin >> yesTax;

if (yesTax == 'Y')
{
withTaxA = (poundPrice * pounds);
withTaxB = (withTaxA * doubleTax);
withTax = (withTaxA + withTaxB);
cout << fixed << setprecision(2);
cout << "Total: $" << withTax << endl;
}
else
{
noTax = poundPrice * pounds;
cout << fixed << setprecision(2);
cout << "Total: $" << noTax << endl;
}
//end if
// system("PAUSE");
return 0;
} //end of main function


/*
output:

Pounds ordered : 56
Price per pound : 2
Does the customer need to be charged sales tax? (Y or N) : Y
Total: $115.92


Pounds ordered : 56
Price per pound : 2
Does the customer need to be charged sales tax? (Y or N) : N
Total: $112.00

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote