0

Can someone debugg the code for me. Its about "void" function. Qn. Make a chat bot & take username as input & output greetings

#include <iostream> using namespace std; void bot() { string name; cin >> name; cout << "Welcome, " <<"Amy"<<"!"; } int main(){ bot(); } Greeting should be like "Welcome, James!"

14th Jan 2023, 11:10 AM
Alex Boso Nzaphila
Alex Boso Nzaphila - avatar
12 Réponses
+ 5
#include <iostream> using namespace std; void bot() { string name; cin >> name; cout << "Welcome, " << name << "!"; // use input value. . } int main(){ bot(); }
14th Jan 2023, 11:59 AM
Jayakrishna 🇮🇳
+ 3
If you need "Welcome, James!" then add James instead of "Amy"! If you need "Welcome " , followed by input name , then add cout<< "Welcome, " << name <<"!";
14th Jan 2023, 11:26 AM
Jayakrishna 🇮🇳
+ 1
It's depends on the task. So add full task description to find mistake if any.. See error terminates program to run. But when you get output but it is wrong then it's logical error of wrong implementation or logic. Convey the correct problem so others understand and you get quick accurate answers... Now what error yoh getting..? Alex Boso Nzaphila : why you using again "Amy"? Do you know what it means cin>>name; where are you using this input name? see my previous first post again.....
14th Jan 2023, 11:40 AM
Jayakrishna 🇮🇳
+ 1
Let me try
14th Jan 2023, 12:01 PM
Alex Boso Nzaphila
Alex Boso Nzaphila - avatar
+ 1
@Jayakrishna the code worked, I was supposed to replace it with the original input. Thanks!
14th Jan 2023, 12:11 PM
Alex Boso Nzaphila
Alex Boso Nzaphila - avatar
+ 1
Good
15th Jan 2023, 5:05 PM
ADWAITH B A
ADWAITH B A - avatar
+ 1
On python that is: name=input() print(f"Welcome {name} !")
16th Jan 2023, 8:38 AM
Артур Янковенко
Артур Янковенко - avatar
0
What's the error there?
14th Jan 2023, 11:10 AM
Alex Boso Nzaphila
Alex Boso Nzaphila - avatar
0
That's correct but there is another error
14th Jan 2023, 11:36 AM
Alex Boso Nzaphila
Alex Boso Nzaphila - avatar
0
#include <iostream> using namespace std; void bot() { string name; name= "Amy"; cin >> name; cout << "Welcome, " <<"Amy"<<"!"; } int main(){ bot(); }
14th Jan 2023, 11:40 AM
Alex Boso Nzaphila
Alex Boso Nzaphila - avatar
0
Alex Boso Nzaphila It works once you replace the hard coded name in the output with the variable. I tested.
14th Jan 2023, 11:56 AM
Lochard
Lochard - avatar
0
Kindly enlighten, I don't understand
14th Jan 2023, 11:59 AM
Alex Boso Nzaphila
Alex Boso Nzaphila - avatar