0

Default arguments

I hade some problem to solve this, then I figure out right answer. Maybe it helps someone else :) Your usual order at your favorite cafe is black tea, which the waiter brings you by default. Today, however, you are with your friend and it is his first time there. Obtain your friend's order in one word as input, and place the order for both of you. Complete the function so that it will output "Black tea" by default (without an argument) and then your friend's order as an argument. Sample Input Americano Sample Output Black tea Americano Here is my code: #include <iostream> #include <string> using namespace std; //complete the function with one default argument string printOrder(string friendOrder, string myOrder="Black tea") { return myOrder + "\n" + friendOrder; } int main() { //getting coffee type string friendOrder; cin >> friendOrder; cout << printOrder(friendOrder); return 0; }

11th Aug 2021, 12:29 PM
Sara N
4 Respostas
+ 2
All pass try this code #include <iostream> #include <string> using namespace std; //complete the function with one default argument void printOrder(string Order="Black tea"){ cout<<Order<<endl; } int main() { //getting coffee type string friendOrder; cin >> friendOrder; printOrder(); cout<<friendOrder; return 0; }
10th Apr 2022, 12:18 PM
Sekh aslam
+ 1
#include <iostream> #include <string> using namespace std; //complete the function with one default argument string printOrder(string friendOrder, string myOrder="Black tea") { return myOrder + "\n" + friendOrder; } int main() { //getting coffee type string friendOrder; cin >> friendOrder; cout << printOrder(friendOrder); return 0; } Good Luck
25th Jan 2022, 5:07 PM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
0
Sara N i didn't understood your question as per my understanding u need to make two methods one for default value another one for parameter passing.
11th Aug 2021, 1:52 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
- 2
tbh, it isn't rocket science.
11th Aug 2021, 12:45 PM
Rellot's screwdriver
Rellot's screwdriver - avatar