Function parameter help | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Function parameter help

I try many solution and I check the answer, but I don't know why my code doesn't work. #include <iostream> using namespace std; void bot(int mode, string name){ if (mode==1){ cout<<"Welcome"<<name<< "!"; } else if (mode==2){ cout << "Goodbye, "<<name<<"!"; } else{ cout << "Try again"; } } int main() { int mode; cin >> mode; string name; cin >> name; bot(mode, name); }

11th May 2023, 8:56 PM
Remi T
Remi T - avatar
2 Respostas
+ 1
side note, if you're allergic to #include for some reason, you can also use the plain C approach (he said evilly) of using char arrays. (yeah, just #include <string>)
11th May 2023, 10:19 PM
Orin Cook
Orin Cook - avatar
0
Look at cout<<ā€œWelcomeā€<<name<<ā€œ!ā€; When you concatenate welcome with name, you are not spliting the words. Example, if input is: 1 Steven Output will be WelcomeSteven! You have to put an space after Welcome That line of code should be like this: cout << ā€œWelcome ā€œ << name << ā€œ!ā€ << endl;
11th May 2023, 9:09 PM
Ugulberto SƔnchez
Ugulberto SƔnchez - avatar