Aug 7, 2008 at 6:57pm UTC
Hi all,
I cannot figure out why the module ApplyTax is not calculating the tax to dNewCost and assigning the variable dSalesTax this value. Instead of doing this, dSales Tax becomes the same value as dNewCost.
When the program runs, the user is asked if today is a sales day.
The user enters Y or N (yes or no). Then the user inputs the values inside the input module. Assuming the user entered Y for the very first question, ApplyDiscount module runs. Afterwards the ApplyTax module runs. Yet the sales tax is not calculated. Any reason as to why this is not working?
All help is greatly appreciated.
float fLength, fHeight, fWidth;
float fCost, fTotalCostWithDiscount, fTotalCostWithTax;
float fOneGallonArea;
float fTotalArea;
double dGallonsNeeded;
string CustFullName;
char state;
char CustFirstName;
char CustLastName;
char userAnswer='y';
char salesAnswer;
double dSalesTax;
double dTotalCost, dNewCost, dNewCost1;
double dDiscount1 = .95, dDiscount2 = .90, dDiscount3 = .85, dDiscount4 = .80;
void Input()
{
SplashScreen("***Acme Paint Shop***");
cout<< left<< setw(21)<< "Customer Name (First and last):";
getline(cin, CustFullName);
cout<< "Height:";
cin>> fHeight;
cout<< "Width:";
cin>> fWidth;
cout<< "Length:";
cin>> fLength;
cout<< setw(22)<< "Gallon coverage:";
cin>> fOneGallonArea;
cout<< "Cost Per Gallon:";
cin>> fCost;
cout<< setw(9)<< "State:";
cin.get(state);
cin.ignore(256, '\n');
CalcArea();
return;
}
void CalcCosts()
{
if ((salesAnswer == 'Y')||(salesAnswer == 'y'))
ApplyDiscount();
else
{
dNewCost=dTotalCost;
ApplyTax();
}
return;
}
void ApplyDiscount()
{
if (toupper(salesAnswer) == ('Y'))
{
if (dGallonsNeeded==1)
dNewCost=dTotalCost * dDiscount1;
else if ((dGallonsNeeded==2)||(dGallonsNeeded==3))
dNewCost=dTotalCost * dDiscount2;
else if (dGallonsNeeded==4)
dNewCost=dTotalCost * dDiscount3;
else if (dGallonsNeeded>4)
dNewCost=dTotalCost * dDiscount4;
}
else
dNewCost=dTotalCost;
ApplyTax();
return;
}
void ApplyTax()
{
dNewCost1=dNewCost;
if (toupper(state)=='GA')
dSalesTax=dNewCost1*1.06;
else if (toupper(state)=='FL')
dSalesTax=dNewCost1*1.04;
else if (toupper(state)=='SC')
dSalesTax=dNewCost1*1.05;
else if (toupper(state)=='TN')
dSalesTax=dNewCost1*1.06;
else if (toupper(state)=='AL')
dSalesTax=dNewCost1*1.02;
else if ((toupper(state)!='GA') && (toupper(state)!='FL')
&& (toupper(state)!='SC') && (toupper(state)!='TN')
&& (toupper(state)!='AL'))
dSalesTax=dNewCost1;
CalcScreen();
return;
}
void CalcScreen()
{
SplashScreen("***Acme Paint Shop***");
cout<< "Customer Name: " <<CustFullName <<endl;
cout<< left<< setw(35)<< "Number of gallons needed:";
cout<< setw(10)<< right<< dGallonsNeeded <<endl;
cout<< left<< setw(35)<< "Cost before discount:";
cout<< setw(10)<< setprecision(2)<< fixed<< right<< dTotalCost <<endl;
cout<< left<< setw(35)<< "Cost after discount:";
cout<< setw(10)<< setprecision(2)<< fixed<< right<< dNewCost <<endl;
cout<< left<< setw(35)<< "Cost with tax:";
cout<< setw(10)<< setprecision(2)<< fixed<< right<< dSalesTax <<endl;
return;
}
Aug 7, 2008 at 8:01pm UTC
Well I have ApplyTax() to run after ApplyDiscount() runs. In ApplyDiscount(),
ApplyTax() is the next to run. I think the problem lies somewhere in ApplyTax().
Thank you for your reply though.
Aug 8, 2008 at 8:27am UTC
Try making state a string rather than a char, (ditto for CustFirstname and CustLastName ) as it's mroe than 1 character long...
You will then need a function to convert it to uppercase (as toupper works just on a single char) to use in CalcTax.