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 TRAN VAN LIEU
Remi TRAN VAN LIEU - avatar
3 ответов
+ 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