Coding Question

Write the code for a method named calculateTax that accepts a double parameter named subTotal and a boolean parameter named isFresno and calculates and returns the sales tax. If isFresno is false, the sales tax should .0775. If it's true, the sales tax should be increased by .001. If the subTotal is less than or equal to zero, an IllegalArgumentException should be thrown with the message "Subtotal must be greater than zero."



So far I believe we need a void statement such as:

void calculateTax(double subtotal, bool isFresno)

but I am not sure where reference and value parameters should be. For instance, I don't know where I should use & to make it a reference parameter. Would the calculate tax be in the main function or the void function?
Feel free to post a code you think would work.











#include<iostream>

using namespace std;


void calculateTax(double& subtotal, bool isFresno);

int main()
{
bool isFresno = false;
double num, sum;
cout<<"Enter number(s): ";
cin>>num;

while (num != -999)
{
sum = sum + num;
cin>>num;
}
if (sum > 100)
isFresno = true;

void calculateTax(sum, isFresno);

return 0;
}

void calculateTax(sum, isFresno)
{
double subTotal = sum;
cout<<"subTotal = "<<subTotal<<endl;

So far, I have this but it is not compiling. It states that void is being used illegally.
[code]Your code goes here[/code]
Remove the void in the calculateTax that is inside main. The compiler thinks that you want to declare a function inside other function.
When define functions the prototypes must match (you aren't writing the types of the parameters)
#include<iostream>

using namespace std;


void calculateTax(double subtotal, bool isFresno, double& salesTax);

int main()
{
double salesTax;
bool isFresno == false;
double num, sum;
cout<<"Enter number(s): ";
cin>>num;

while (num != -999)
{
sum = sum + num;
cin>>num;
}
if (sum > 100)
isFresno == true;

void calculateTax(sum, isFresno, salesTax);
cout<<salesTax;

return 0;
}

void calculateTax(sum, isFresno, salesTax)
{
double subTotal = sum;
if (isFresno = true)
salesTax = subTotal * (.0775 + .001)
else
salesTax = subTotal * .0775
cout<<"subTotal = "<<subTotal<<endl;
}


I have made the changes but I cannot get it to work.
Topic archived. No new replies allowed.