+ 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); }
7 Réponses
+ 8
Do you have to include a space after the commas, like "Weclome, "/"Goodbye, "?
+ 8
Is this from a task? Can you add the task description please?
+ 7
As far as I have seen, it hasn't made any difference till now
+ 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
+ 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".
+ 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.
+ 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 .