Getting errors, not sure how to fix

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2008
Posts: 16
Reputation: cout<<"alias" is an unknown quantity at this point 
Solved Threads: 1
cout<<"alias" cout<<"alias" is offline Offline
Newbie Poster

Getting errors, not sure how to fix

 
0
  #1
Nov 23rd, 2008
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.

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. double payrate;
  8. double hours;
  9. double overtimehours;
  10. double overtimepay;
  11. double totalpay;
  12.  
  13. cout << "How many hours did client work this week?" << endl ;
  14. cin >> hours ;
  15. cout << "What is their current payrate?" << endl ;
  16. cin >> payrate ;
  17.  
  18. if (payrate < 10) && (hours > 40)
  19. overtimehours = hours - 40 ;
  20. overtimepay = overtimehours * 1.5 * payrate ;
  21. totalpay = 40 * payrate + overtimepay ;
  22. cout << "The client worked overtime, they are owed: $" << totalpay << endl ;
  23. else
  24. totalpay = hours * payrate ;
  25. cout << "The client is owed: $" << totalpay << endl ;
  26.  
  27. return 0 ;
  28.  
  29. }

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
Last edited by cout<<"alias"; Nov 23rd, 2008 at 7:41 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 158
Reputation: cam875 is an unknown quantity at this point 
Solved Threads: 3
cam875 cam875 is offline Offline
Junior Poster

Re: Getting errors, not sure how to fix

 
0
  #2
Nov 23rd, 2008
You messed up your if statement and forgot the braces on the if and else statements, heres the fixed code, good luck.

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. double payrate;
  7. double hours;
  8. double overtimehours;
  9. double overtimepay;
  10. double totalpay;
  11.  
  12. cout << "How many hours did client work this week?" << endl ;
  13. cin >> hours ;
  14. cout << "What is their current payrate?" << endl ;
  15. cin >> payrate ;
  16.  
  17. if (payrate < 10 && hours > 40)
  18. {
  19. overtimehours = hours - 40 ;
  20. overtimepay = overtimehours * 1.5 * payrate ;
  21. totalpay = 40 * payrate + overtimepay ;
  22. cout << "The client worked overtime, they are owed: $" << totalpay << endl ;
  23. }
  24.  
  25. else
  26. {
  27. totalpay = hours * payrate ;
  28. cout << "The client is owed: $" << totalpay << endl ;
  29. }
  30.  
  31. return 0 ;
  32.  
  33. }
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 320
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 63
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: Getting errors, not sure how to fix

 
0
  #3
Nov 23rd, 2008
Should be..
  1. if(payrate < 10 && hours > 40)
  2. { // begin if
  3. //-- your code here
  4. } // end if
  5. else
  6. //...Else
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 16
Reputation: cout<<"alias" is an unknown quantity at this point 
Solved Threads: 1
cout<<"alias" cout<<"alias" is offline Offline
Newbie Poster

Re: Getting errors, not sure how to fix

 
0
  #4
Nov 24th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC