943,696 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 551
  • C++ RSS
Nov 23rd, 2008
0

Getting errors, not sure how to fix

Expand Post »
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.

c++ Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
cout<<"alias" is offline Offline
16 posts
since Nov 2008
Nov 23rd, 2008
0

Re: Getting errors, not sure how to fix

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

C++ Syntax (Toggle Plain Text)
  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. }
Reputation Points: 12
Solved Threads: 4
Junior Poster
cam875 is offline Offline
170 posts
since Jun 2008
Nov 23rd, 2008
0

Re: Getting errors, not sure how to fix

Should be..
c++ Syntax (Toggle Plain Text)
  1. if(payrate < 10 && hours > 40)
  2. { // begin if
  3. //-- your code here
  4. } // end if
  5. else
  6. //...Else
Reputation Points: 47
Solved Threads: 69
Posting Whiz
cikara21 is offline Offline
340 posts
since Jul 2008
Nov 24th, 2008
0

Re: Getting errors, not sure how to fix

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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
cout<<"alias" is offline Offline
16 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Does BOOST support MVS
Next Thread in C++ Forum Timeline: map of arrays?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC