+ 6

Hello All, I am not getting this, kindly guide me. I searched for this in the QnA section also.

The Code that I have tried: #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); }

15th May 2023, 2:53 PM
Coding Caesar🎯
Coding Caesar🎯 - avatar
7 Respuestas
+ 8
Do you have to include a space after the commas, like "Weclome, "/"Goodbye, "?
15th May 2023, 3:02 PM
Ausgrindtube
Ausgrindtube - avatar
+ 8
Is this from a task? Can you add the task description please?
15th May 2023, 3:10 PM
Ausgrindtube
Ausgrindtube - avatar
+ 7
As far as I have seen, it hasn't made any difference till now
15th May 2023, 3:08 PM
Coding Caesar🎯
Coding Caesar🎯 - avatar
+ 5
Here it is : Chat Bot v2 Let's make our chat bot a bit more advanced using parameters! The bot() function has to take 2 parameters: one integer called mode, and a string called name. The given code takes the values for the arguments as input and passes them to the bot() function. Modify the bot() function to take the START SOLVING
15th May 2023, 3:17 PM
Coding Caesar🎯
Coding Caesar🎯 - avatar
+ 4
arguments as input and passes them to the bot()unction. Modify the bot() function to take the given 2 parameters and generate the output using the following logic: • In case mode is 1, the output should be "Welcome, name!", where name is the parameter's value. • In case mode is 2, the output should be "Goodbye, name!". • If mode has any other value, the output should be "Try again".
15th May 2023, 3:18 PM
Coding Caesar🎯
Coding Caesar🎯 - avatar
+ 3
Definitely works in general, but you'll definitely need to add those spaces. Other than that, the only issue I can think of is if you're supposed to be able to accept full names (ie space separated names), in which case cin will only take the first one.
15th May 2023, 6:48 PM
Orin Cook
Orin Cook - avatar
+ 3
Yes, it worked in general but not in the code task. Now, I removed all the spaces and reposted it and it worked. Thanks Ausgrindtube , Orin Cook .
15th May 2023, 11:12 PM
Coding Caesar🎯
Coding Caesar🎯 - avatar