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); }
2 odpowiedzi
+ 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>)
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;