0

Random unwanted number printed.

I am trying to complete a challenge that I think I understand. However, after running the code, the answer is incorrect since an extra number prints, the number 1, it's making it wrong for all cases.

2nd Jun 2021, 6:05 AM
TeAiris Majors
TeAiris Majors - avatar
7 Respuestas
+ 2
I think you should swap a and b in output done inside 'printOrder' function, and remove the 'cout' line in your 'main' function ^^
2nd Jun 2021, 6:13 AM
visph
visph - avatar
+ 1
what is the purpose of your line: cout << printOrder << endl; ???
2nd Jun 2021, 6:10 AM
visph
visph - avatar
+ 1
Thanks! I had figured it out right before see your reply .
2nd Jun 2021, 6:19 AM
TeAiris Majors
TeAiris Majors - avatar
+ 1
#include <iostream> #include <string> using namespace std; //complete the function with one default arg:ument void printOrder(string a, string b = "Black tea") { cout << b << "\n"; cout << a << "\n"; } int main() { //getting coffee type string friendOrder; cin >> friendOrder; printOrder(friendOrder); return 0; }
2nd Jun 2021, 6:19 AM
TeAiris Majors
TeAiris Majors - avatar
+ 1
I just remembered that i dont have to print printOrder because that's the literal purpose of the function 😂 i didn't want to let it do it's job . Also I'm assuming since i did print it, that's where the 1 came from. I'm so tired I was thinking too hard. I guess this is why we debug 😂
2nd Jun 2021, 6:23 AM
TeAiris Majors
TeAiris Majors - avatar
0
#include <iostream> #include <string> using namespace std; //complete the function with one default arg:ument void printOrder(string a, string b = "Black tea") { cout << a << "\n"; cout << b << "\n"; } int main() { //getting coffee type string friendOrder; cin >> friendOrder; printOrder(friendOrder); cout << printOrder << endl; return 0; }
2nd Jun 2021, 6:07 AM
TeAiris Majors
TeAiris Majors - avatar
0
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
2nd Jun 2021, 6:10 AM
TeAiris Majors
TeAiris Majors - avatar