c++ - Expected unqualified-id before '{' token -


i'm trying write program generate labor times based on labor rate, , i'm running expected unqualified-id before '{' token error.

include <iostream> using namespace std;  double s516 = 5.5; // 516-70 alloy welds @ 5.5 inches per minute double a304 = 4.3; // a304 steel welds @ 4.3 inches per minute double x; // value placeholder total linear inches welded  int main()  {     cout << "please enter total number of inches welded:\n ";     cin >> x; }     {         if s516, multiplies[(s516 * x *1.1 / 60];         else if a304, multiplies[(a304 * x * 1.1 / 60];     } 

am on right track of this?

try this:

#include <iostream> using namespace std;  double s516 = 5.5; // 516-70 alloy welds @ 5.5 inches per minute double a304 = 4.3; // a304 steel welds @ 4.3 inches per minute   enum material {     material_s516 = 1,     material_a304 = 2 };  int main() {     double x; // value placeholder total linear inches welded     cout << "please enter total number of inches welded:" << endl;     cin >> x;      int material_to_weld;     cout << "please indicate material have weld (enter 1 s516 or 2 a304):" << endl;     cin >> material_to_weld;      double time_to_weld, corrected_time_to_weld;     if (material_to_weld == material_s516) {         time_to_weld = s516 * x * 1.1 / 60;         corrected_time_to_weld = x * 1.1 / s516 / 60;     } else if (material_to_weld == material_a304) {         time_to_weld = a304 * x * 1.1 / 60;         corrected_time_to_weld = x * 1.1 / a304 / 60;     } else {         cout << "invalid material! please choose either 1 or 2!" << endl;         return(1);     }      cout << "with original formula, welding " << x << " inches of material take " << time_to_weld << " hours." << endl;     cout << "with corrected formula, welding " << x << " inches of material take " << corrected_time_to_weld << " hours." << endl;      return 0; } 

this not how write it, tried keep simple. 1 thing should notice formula looks wrong - time required weld increases speed. time = space / speed, think want use x * 1.1 / s516 / 60. way if speed increases time decreases, expected. anyway have kept both calculations.

as can see, code inside main() function. in code was, yes, inside braces, braces had no meaning, , outside of main(). error got cryptic, that's meant.

some more remarks:

  • it's #include, not include!
  • your s516 , a304 variables declared global variables, because outside of main(). left them there, move them main(). in case there's no practical difference, it's practice use global variables when really need them (which can happen, seldom).
  • as told in comments, need 1 more variable choice of material, , corresponding cout , cin. please note when read input user should validate it, is, check it's valid. here, example, accepted values 1 , 2, , if user enters 3 program display "invalid material! please choose either 1 or 2!" , terminate. approach insert loop, keeps asking user choose either 1 or 2, , loop stops after user has provided valid input
  • i have used enum material. enums safer ints, haven't used in way. still, it's lot of stuff study, , i've decided keep simple, have used this.

i hope can you.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -