Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

error: expected constructor, destructor, or type conversion before ‘int’

0 votes
asked Nov 23, 2023 by Josvanth Krethik S (170 points)
 error: expected constructor, destructor, or type conversion before ‘int’
    8 | int main()
      | ^~~
I am getting this error pls help me!

1 Answer

0 votes
answered Nov 27, 2023 by Peter Minarik (86,240 points)
The problem is probably with your lines above line 8.

Could you please share all your code?
commented Nov 29, 2023 by Josvanth Krethik S (170 points)
The full code is:-

#include <iostream>

using namespace std;

int val = 10;
divide (int)

int main()
{
    int val = 5;
    val = divide(::val/val);
    cout << ::val<<val;
}

int divide(int v)
{
 return v / 2;    
}
commented Nov 29, 2023 by Peter Minarik (86,240 points)
Replace line 6 with this:

int divide (int);

The point is, that when you declare your function, you need to match the signature of your definition and finish with a semicolon.

E.g.: [type] [name]([arguments]);

Furthermore, you'd want to put some space between the numbers you print, like this:

std::cout << ::val << ", " << val << std::endl;
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...