473,378 Members | 1,218 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Error for expected unqualified-id before '{' token

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
1 4629
donbock
2,426 Expert 2GB
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

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

Similar topics

21
by: Ram Prasad | last post by:
I am trying to write a simple libspf2 plugin code for my postfix ( milter) I am getting this unhelpful error message when I try to compile gcc -g1 -Wall -I/usr/local/include/spf2 -I. -c mfunc.c...
5
by: gyre | last post by:
Hi! I've got a little problem I've been dealing with for several days :(( Code is written in Qt. I'll try to explain it: I created an abstract class "VcaNode" with 4 virtual methods and 3 other...
5
by: amitmool | last post by:
hi, i have used the queue library file and try to use the template as template <class QueueItem> queue <QueueItem>::~queue() // line 25 { } template <class QueueItem> void...
5
by: nina01 | last post by:
Hi! I'm working on a mini compiler with flex and bison. The ".l" and ".y" files are generated successfully. However, when I try to compile the hole thing using the command "gcc -o comp comp.tab.c...
1
by: bals3239 | last post by:
I am using a program called putty to write basic programs in C/ C++ for an introduction to computer programming class. I am very new at programming and am just getting started writing very simple...
12
by: sam23 | last post by:
Hi all, im new to this programming language and i tried to use my Xcode to build and run this code but i got a error :(, and another error is i need a help guys #include <GLUT/glut.h>...
4
by: KBeggs | last post by:
Hi. I'm working on a program for a class that requires me to make a checking account simulator. However, every time I try to compile it, I get errors. I have gotten it down to very minimal errors,...
2
by: gretakola | last post by:
hi can anyone help me?? is this code i dont know if is right or not, i am new in c++ #include <iostream> using namespace std; template < Typename T> bool T xor(const T& a, const T& b) {...
3
by: AffinityCreate | last post by:
Hi I am trying to add the DS1307 to my project via I2C using both a keypad and LCD. So far I have been able to get my project working with a passcode entry, led, keypad input and LCD display. I as...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.