Expected primary expressions

I am trying to write a program that computes taxes. I keep receiving error mesages saying that there are expected primary expressions before certain things in my program. If anyone could please help me I would greatly appreciate it!!! Thank you :)

#include <iostream>
#include <string>
using namespace std;

int main ()
{
double tax;
double income;

cout << "Please enter your income: " ;
cin >> income;

cout << "Please enter s for single, m for married: ";
string marital_status;
cin >> marital_status;
{
if (marital_status == "s" )
{
if (income => 0 && income <= 8000);
tax = .1 * income;
else if (income > 8000 && income <= 32000);
tax = 800 + .15 * income;
else
(income > 32000)
tax = 4400 + .25 * income;
}
if (marital_status == "m" )
{
if (income => 0 && income <= 16000);
tax = .1 * income
else if (income > 16000 && income <= 64000);
tax = 1600 + .15 * income
else
(income > 64000)
tax = 8800 + .25 * income
}

cout << "The tax is $" << total_tax << endl;
system ("pause");
return 0;
}
if/else/else-if statements should not have a ; at the end of them, however the statements inside of them do. Also => should be written as >=.
1
2
if (income >= 0 && income <= 16000)
tax = .1 * income;

else statements shouldn't have any condition like you have here. Either delete the condition or change it to else if.
1
2
else 
(income > 64000)


Finally are using a total_tax variable at the end of main but I don't see it declared anywhere.
Last edited on
I fixed everything, but it says expected '}' at end of input on my last line and I don't know why.

#include <iostream>
#include <string>
using namespace std;

int main ()
{
double tax;
double income;

cout << "Please enter your income: " ;
cin >> income;

cout << "Please enter s for single, m for married: ";
string marital_status;
cin >> marital_status;
{
if (marital_status == "s" )
{
if (income >= 0 && income <= 8000)
tax = .1 * income;
else if (income > 8000 && income <= 32000)
tax = 800 + .15 * income;
else
tax = 4400 + .25 * income;
}
if (marital_status == "m" )
{
if (income >= 0 && income <= 16000)
tax = .1 * income;
else if (income > 16000 && income <= 64000)
tax = 1600 + .15 * income;
else
tax = 8800 + .25 * income;
}
cout << "The tax is $" << tax << endl;
system ("pause");
return 0;
}
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
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

int main ()
{
double tax;
double income;

cout << "Please enter your income: " ;
cin >> income;

cout << "Please enter s for single, m for married: ";
string marital_status;
cin >> marital_status;
{
if (marital_status == "s" )
{
if (income >= 0 && income <= 8000)
tax = .1 * income;
else if (income > 8000 && income <= 32000)
tax = 800 + .15 * income;
else
tax = 4400 + .25 * income;
}
if (marital_status == "m" )
{
if (income >= 0 && income <= 16000)
tax = .1 * income;
else if (income > 16000 && income <= 64000)
tax = 1600 + .15 * income;
else
tax = 8800 + .25 * income;
}
cout << "The tax is $" << tax << endl;
system ("pause");
return 0;
}
}    //you forgot to close the main function's block 



Also, I recommend you use an editor like notepad++ cause it highlights any (,),{ and }, so you easily detect these kind of errors.
If you indent the code properly these kind of errors is easy to spot.
Topic archived. No new replies allowed.