+ 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 :)
11 Respostas
+ 9
I would structure the code like this:
https://code.sololearn.com/c2JzgxXwhJ2j/?ref=app
But it is just the way I like things :)
+ 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
+ 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);
}
+ 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.
+ 1
I understand, so i always need my main function to call the function that i created.
+ 1
uuuuuhhhhhh I prefer the @Tobias code :)
+ 1
OK 😄
+ 1
Thanks to you i did this :
https://code.sololearn.com/cTa0tqm5QJtd/?ref=app
0
But this is a function !
I want that my function(ajoutedeux) add two at the variable "nr"
0
Thank you a lots !!!