Hi there, been having some trouble with a simple program i am trying to write. I'm fairly new to C++, and can't seem to fix the errors im getting. Any ideas or hints would be much appreciated.

#include <iostream>

using namespace std; 

int main()
{
     double payrate;
		 double hours;
		 double overtimehours;
		 double overtimepay;
		 double totalpay;

    cout << "How many hours did client work this week?" << endl ;
	cin >> hours ;
	cout << "What is their current payrate?" << endl ;
	cin >> payrate ;

	if (payrate < 10) && (hours > 40)
    overtimehours = hours - 40 ;
	overtimepay = overtimehours * 1.5 * payrate ;
	totalpay = 40 * payrate + overtimepay ;
	cout << "The client worked overtime, they are owed: $" << totalpay << endl ;
	else  
    totalpay = hours * payrate ;
    cout << "The client is owed: $" << totalpay << endl ;
	 
	return 0 ;  

}

These are the errors im getting;

c:\documents and settings\owner\my documents\visual studio 2008\projects\practice\practice\payrate.cpp(18) : error C2143: syntax error : missing ';' before '&&'

c:\documents and settings\owner\my documents\visual studio 2008\projects\practice\practice\payrate.cpp(18) : warning C4390: ';' : empty controlled statement found; is this the intent?

c:\documents and settings\owner\my documents\visual studio 2008\projects\practice\practice\payrate.cpp(23) : error C2181: illegal else without matching if

Again, any hints in the right direction here are much appreciated.

-alias

You messed up your if statement and forgot the braces on the if and else statements, heres the fixed code, good luck.

#include <iostream>
using namespace std; 

int main()
{
double payrate;
double hours;
double overtimehours;
double overtimepay;
double totalpay;

cout << "How many hours did client work this week?" << endl ;
cin >> hours ;
cout << "What is their current payrate?" << endl ;
cin >> payrate ;

if (payrate < 10 && hours > 40)
{
overtimehours = hours - 40 ;
overtimepay = overtimehours * 1.5 * payrate ;
totalpay = 40 * payrate + overtimepay ;
cout << "The client worked overtime, they are owed: $" << totalpay << endl ;
}

else 
{ 
totalpay = hours * payrate ;
cout << "The client is owed: $" << totalpay << endl ;
}
	 
return 0 ;  

}

Should be..

if(payrate < 10 && hours > 40)
{ // begin if
   //-- your code here
} // end if
else
   //...Else

wow, that was a pretty simple fix. I wasnt sure if i needed to include the brackets after the "if" statement, that does help alot. Thanks again guys, really cleared that up for me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.