Cannot get this code to work

#include<iostream>

using namespace std;


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

int main()
{
double salesTax=0;
bool isFresno = false;
double num=0, sum=0;

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<<"salesTax = "<<salesTax<<endl;
}
Your question is...?
I am getting the following errors
Error 1 error C2182: 'calculateTax' : illegal use of type 'void' 25
Error 2 error C2078: too many initializers 25
Error 4 error C2448: 'calculateTax' : function-style initializer appears to be a function definition 32




I believe I am writing the void code wrong, if anyone can help me I really appreciate it.
I edited so it would run...I didnt bother to see if it does what you want but it will run. Your function implementation is wrong, and your not testing a value when you do if(isFresno = true). Thats assigning isFresno to true you need ==

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

#include<iostream>

using namespace std;


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

int main()
{
    double salesTax=0;
    bool isFresno = false;
    double num=0, sum=0;

    cout<<"Enter number(s): ";
    cin>>num;

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


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

return 0;
}

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

I have edited the code, but it is not giving me the answers I would expect to get. I tried to be more detailed about what I wanted to accomplish.

/*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."*/



#include<iostream>

using namespace std;


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

int main()
{
double salesTax=0.0;
bool isFresno = false; //assigning the value of false
double num=0.0, sum=0.0;

cout<<"Enter number(s): ";
cin>>num;

while (num != -999)
{
sum = sum + num;
cin>>num;
}
if (sum > 100.0)
isFresno = true; //if sum is greater than 100, then//
//change value of isFresno to true//
calculateTax(sum, isFresno, salesTax);
cout<<"salesTax is "<<salesTax<<endl;

return 0;
}

void calculateTax(double subTotal, bool isFresno, double& salesTax)
{
int rate1 = (.0775 + .001);
int rate2 = .0775;
if (isFresno == true)
{
salesTax = subTotal * rate1;
cout<<"rate1 is "<<rate1<<endl;
}
else
{
salesTax = subTotal * rate2;
cout<<"rate2 is "<<rate2<<endl;
}

}
Topic archived. No new replies allowed.