New course! Every coder should learn Generative AI!
Try a free lesson+ 1
You have misunderstood the concept the procedure should be inside the function
#include <iostream>
using namespace std;
int timesTwo(int x) {
return x*2;
}
int main() {
cout << timesTwo(8) << endl;
return 0;
}
+ 1
Actually tere are two types of this
1. Functions
2. Sub Routine
FUNCTION
It takes an input and gives a output after processing the input
SUB ROUTINE
It takes an Input and do something but do not return any thing.
In c++ Defining Function and Sub Routines are same}
If you do not want to return anything follow this template
void function-name(parameters){...}
0
It's not necessary that a function returns only int
It depends on its defination
General template of function
Data-Type Function-name(parameter){
...
}
data -type defines which type is returned by function
void means it do not return anything