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!"
12 Antworten
+ 5
#include <iostream>
using namespace std;
void bot() {
string name;
cin >> name;
cout << "Welcome, " << name << "!"; // use input value. .
}
int main(){
bot();
}
+ 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 <<"!";
+ 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.....
+ 1
Let me try
+ 1
@Jayakrishna the code worked, I was supposed to replace it with the original input.
Thanks!
+ 1
Good
+ 1
On python that is:
name=input()
print(f"Welcome {name} !")
0
What's the error there?
0
That's correct but there is another error
0
#include <iostream>
using namespace std;
void bot() {
string name;
name= "Amy";
cin >> name;
cout << "Welcome, " <<"Amy"<<"!";
}
int main(){
bot();
}
0
Alex Boso Nzaphila It works once you replace the hard coded name in the output with the variable. I tested.
0
Kindly enlighten, I don't understand