Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I keep getting this error:
error C2143: syntax error : missing ';' before '}'

C++
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

int main(int argc, const char * argv[])
{
ifstream input;
input.open("text.txt");

int employeeid, numberofemployees;
float hourlyrate, grosspay, hoursworked , taxamount, netpay;
float taxrate=0;
char taxstatus[2];

numberofemployees=0;

while (input>>employeeid>>hoursworked>>hourlyrate>>taxstatus){

grosspay = hoursworked*hourlyrate;

if (grosspay > 1000) taxrate= 0.30;
else if (grosspay > 800 ) taxrate=  0.20;
else if (grosspay > 500) taxrate = 0.10;
else taxrate=0.0;
ifstream input;
if ((((strcmp(taxstatus, "H")==0))||((strcmp(taxstatus, "h")==0))) && (grosspay>500)){
taxrate=taxrate-.05;
}
ifstream input;
if ((((strcmp(taxstatus, "S")==0))||((strcmp(taxstatus, "s")==0))){
taxrate=taxrate-.05;
}
ifstream input;
if ((((strcmp(taxstatus, "M")==0))||((strcmp(taxstatus, "m")==0))){
taxrate=taxrate-.05;

}
taxamount=grosspay*taxrate;
netpay=grosspay-taxamount;
cout<<"THE EMPLOYEE ID IS:"<< employeeid<<endl;
cout<<"THE HOURS WORKED ARE:" <<hoursworked<<endl;
cout<<"THE HOURLY RATE IS:"<< hourlyrate<<endl;
cout<<"THE GROSS PAY IS:" <<grosspay<<endl;
cout<<"THE TAXAMOUNT IS:"<< taxamount<<endl;
cout<<"THE NET PAY IS:"<< netpay<<endl;

}
input.close();
system("pause");
return 0;
}
Posted
Updated 18-Jun-14 14:46pm
v4
Comments
PIEBALDconsult 18-Jun-14 20:48pm    
Doesn't it say which line?
Member 10893567 18-Jun-14 20:55pm    
Yes it says line 53, which is the last line with }
PIEBALDconsult 18-Jun-14 22:59pm    
I think you need a better compiler.
Stefan_Lang 19-Jun-14 3:07am    
Actually all he needs is a better editor - mine (using VS with VisualAssist) immediately pointed out the surplus opening brackets in the last two if statements. Alternately it might be a missing closing bracket as suggested in Solution 2, I didn't bother to check which it is ;-)
PIEBALDconsult 19-Jun-14 9:07am    
The editor doesn't produce error messages.

Add one bracket in both these lines

C++
if ((((strcmp(taxstatus, "S")==0))||((strcmp(taxstatus, "s")==0)))){


if ((((strcmp(taxstatus, "M")==0))||((strcmp(taxstatus, "m")==0)))){
 
Share this answer
 
Comments
Stefan_Lang 19-Jun-14 3:08am    
Yup, that's what my editor said, too. +5
PIEBALDconsult 19-Jun-14 11:16am    
Certainly not a bracket.
it is a bracket too much opened, but write cleaner code:

C++
if ((((strcmp(taxstatus, "H")==0))||((strcmp(taxstatus, "h")==0))) && (grosspay>500)){

//is is enough bur use space
if ( ( (strcmp(taxstatus, "H")==0) || ((strcmp(taxstatus, "h")==0) && (grosspay>500) ) {


instead of
strcmp(taxstatus, "S")==0)


you better write

switch( taxstatus[0] )
{
case 'H:'
case 'h':


because it is a single character!!!

input.open("text.txt"); //file should have a full path
 
Share this answer
 
Isn't .05 an invalid numeric literal? Just guessing here.



Huh. Seems I'm wrong. I've never seen anyone actually begin a floating point (or related) literal with the decimal point and would never do so myself, but it appears to be OK. Weird.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900