Why do my programm doesn't work ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why do my programm doesn't work ?

#include <iostream> using namespace std; int ajoutedeux(int nr){ cin>>nr; int resultat = nr + 2; cout<<"Le resultat est"<<resultat<<endl; return resultat; } PS : I'm french :)

29th Dec 2017, 9:22 AM
Valkyrion
Valkyrion - avatar
11 Answers
+ 9
I would structure the code like this: https://code.sololearn.com/c2JzgxXwhJ2j/?ref=app But it is just the way I like things :)
29th Dec 2017, 10:35 AM
jay
jay - avatar
+ 8
:) Tobias is correct, they both provide the same result in this context I just like portability and I believe functions should be independent as possible. But as I said, earlier, it is just the way I like things
29th Dec 2017, 10:42 AM
jay
jay - avatar
+ 5
@Valkryion You need to declare a main function as well and call ajoutedeux in that for ajoutedeux to work. Main serves as the entry point for all C++ applications and it is necessary for all C++ programs to have a main function. So the final code will be : #include <iostream> using namespace std; int ajoutedeux(int nr){ cin>>nr; int resultat = nr + 2; cout<<"Le resultat est"<<resultat<<endl; return resultat; } int main() { int nombre; ajoutedeux(nombre); }
29th Dec 2017, 10:00 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 4
It should be int main(int nr) in the place of int ajoutedeux(int nr). The main method is required by the c++ code to work. You should remove your int ajoutedeux and then add int ain in it's place.
29th Dec 2017, 9:30 AM
Akash Pal
Akash Pal - avatar
+ 1
I understand, so i always need my main function to call the function that i created.
29th Dec 2017, 10:08 AM
Valkyrion
Valkyrion - avatar
+ 1
uuuuuhhhhhh I prefer the @Tobias code :)
29th Dec 2017, 10:37 AM
Valkyrion
Valkyrion - avatar
+ 1
OK 😄
29th Dec 2017, 10:43 AM
Valkyrion
Valkyrion - avatar
29th Dec 2017, 10:46 AM
Valkyrion
Valkyrion - avatar
0
But this is a function ! I want that my function(ajoutedeux) add two at the variable "nr"
29th Dec 2017, 9:33 AM
Valkyrion
Valkyrion - avatar
29th Dec 2017, 9:49 AM
Valkyrion
Valkyrion - avatar
0
Thank you a lots !!!
29th Dec 2017, 10:06 AM
Valkyrion
Valkyrion - avatar