943,840 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 374
  • C++ RSS
Oct 19th, 2008
0

Syntax Error

Expand Post »
I am going back through some old code I wrote last year during school to try and refresh myself for upcoming classes. This one code I went back and tried to build it and I receive this following error: error C2059: syntax error : 'return'. I am not sure why I am getting this exactly but I am almost certain it has to do with my do while loop. Any help on fixing this error will be appreciated.

Note: I tried to make sure all my braces lined up and for each open there was a closing. I could have missed one though.

C++ Syntax (Toggle Plain Text)
  1. HEADER.H
  2.  
  3. #ifndef WORKER_H
  4. #define WORKER_H
  5.  
  6.  
  7. #include <cstdlib>
  8.  
  9. #include <iostream>
  10.  
  11. #include <iomanip>
  12.  
  13. #include <string>
  14.  
  15. using namespace std;
  16.  
  17. const double REGWEEK = 20.0,
  18. U_RATE = 2.0,
  19. N_RATE = 1.5,
  20. T_RATE = 1.25;
  21.  
  22. #endif
  23.  
  24. //=======================
  25.  
  26. Main.cpp
  27.  
  28. #include "worker.h"
  29.  
  30. int main()
  31. {
  32.  
  33. // Defining variables
  34.  
  35. double hours = 0.0, rate = 0.0, regpay = 0.0, othours = 0.0,
  36. otrate = 0.0, gross = 0.0, otpay = 0.0, posrate = 0.0;
  37.  
  38. char position;
  39. char chioce;
  40. string emp;
  41.  
  42. do{
  43.  
  44. //Collect Employee's Name
  45.  
  46. cout << "Before you begin please...\n"
  47. << "Enter the employee's name: ";
  48.  
  49. cin >> emp;
  50.  
  51. cout << endl;
  52.  
  53. // Main Menu
  54. // Display Main Menu to user with chioces and read in the users chioce
  55.  
  56. cout << "Main Menu" << endl;
  57. cout << "Please enter one of the following options" << endl;
  58. cout << "U - Union\n"
  59. << "N - Non Union\n"
  60. << "T - Temporary" << endl << endl;
  61. cout << "Enter your employee's status: ";
  62.  
  63. cin >> position;
  64.  
  65. cout << endl;
  66.  
  67. if( position == 'U' || position == 'u' ){
  68.  
  69. posrate = U_RATE;
  70.  
  71. } // end of if pos == U
  72.  
  73. if( position == 'N' || position == 'n' ){
  74.  
  75. posrate = N_RATE;
  76.  
  77. } // end of if pos == Non
  78.  
  79. if( position == 'T' || position == 't' ){
  80.  
  81. posrate = T_RATE;
  82.  
  83. } // end of if pos == T
  84.  
  85.  
  86. // Collect Information About Employee
  87.  
  88. cout << "Enter the number of hours " << emp << " worked: ";
  89.  
  90. cin >> hours;
  91.  
  92. cout << endl;
  93.  
  94. cout << "Enter the pay rate that " << emp << " receives: ";
  95.  
  96. cin >> rate;
  97.  
  98. cout << endl;
  99.  
  100.  
  101. // Calculate Employees' Payment Amount
  102.  
  103. if( hours <= REGWEEK ){ // runs code if the user has worked 20 hours or less a week
  104.  
  105. gross = hours * rate;
  106.  
  107. } // end of if hours <= REGWEEK
  108. else{
  109.  
  110. regpay = REGWEEK *rate;
  111.  
  112. othours = hours - REGWEEK;
  113.  
  114. otrate = posrate * rate;
  115.  
  116. otpay = othours * otrate;
  117.  
  118. gross = otpay + regpay;
  119.  
  120.  
  121. } // end of else hour > REGWEEK
  122.  
  123. cout << emp << endl << "Gross Amount" << setw(10) << setfill('.')
  124. << "$" << gross << endl << endl;
  125.  
  126. //Ask User If They Wish to Continue and Proceed Accordingly
  127.  
  128. cout << "Would you like to continue to another employee?"
  129. << "\ny - yes\nn - no"
  130. << "\nEnter chioce now: ";
  131.  
  132. cin >> chioce;
  133.  
  134. cout << endl;
  135.  
  136. while( chioce != 'n' );}
  137.  
  138. return EXIT_SUCCESS;
  139.  
  140. } // end of main
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
buddha527 is offline Offline
21 posts
since Mar 2008
Oct 19th, 2008
1

Re: Syntax Error

while( chioce != 'n' );} should actually be:
} while( chioce != 'n' );
Have a nice coding
Reputation Points: 110
Solved Threads: 43
Posting Whiz in Training
Sci@phy is offline Offline
279 posts
since Sep 2008
Oct 19th, 2008
0

Re: Syntax Error

Thanks that worked perfectly
Reputation Points: 10
Solved Threads: 0
Newbie Poster
buddha527 is offline Offline
21 posts
since Mar 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: Question about Inheritance/Classes
Next Thread in C++ Forum Timeline: any articles or books about pointer?





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


Follow us on Twitter


© 2011 DaniWeb® LLC