By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,677 Members | 1,069 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,677 IT Pros & Developers. It's quick & easy.

Error for expected unqualified-id before '{' token

P: 1
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. using namespace std;
  3. int numOne = 8,numtwo = 2;
  4. {
  5.     return (numOne + numtwo);
  6. }
  7. inline int mul(int numOne, int numtwo)
  8. {
  9.     return(numOne*numtwo);
  10. }
  11. int main()
  12. {
  13.     int numOne = 8, numtwo = 2; 
  14.     cout << "Enter two numbers:";
  15.     cin >> numOne >>numtwo;
  16.     cout << "Sum=";
  17.     cout << "\nProduct=" << mul(numOne, numtwo);
  18.  
  19. }


What is my problem and how can I correct it? Everything I try I get the same error here.
Apr 13 '19 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 2,400
Typically the error message identifies a line number. It would help if you provided that line number (relative to the line numbering in your code snippet).

However, I'm pretty sure the error message refers to the '{' on line 4. Line 3 defines two variables; line 4 starts the body of a function. However there is no function definition (as there are on lines 7 and 11).

Furthermore, you probably want line 16 to include a call to this still-to-be-named function that begins on line 4.

I notice that lines 3 and 13 are identical. There is no need for the variable definitions on line 3. The definitions on line 13 are sufficient.

It is ok to use the same variable names (numOne and numtwo) in main, mul, and unnamed functions but those variables are not connected the way you might think. It may be less confusing to use different names in each function. For example, in mul you might have variables multiplier and multiplicand; and in the unnamed function you might have addend1 and addend2. These names clearly describe what the variables mean in the context of each function.
Apr 17 '19 #2

Post your reply

Sign in to post your reply or Sign up for a free account.