0
[Practice 41.2] Why does my code output ‘1’?
Hello, I’m currently stuck on Practice 41.2 but I’m not sure what’s wrong with my code. It keeps outputting 1 for an odd reason, despite all of the data types being ‘string’. Here’s my code: #include <iostream> #include <string> using namespace std; //complete the function with one default argument void printOrder (string a, string b="Black_tea") { } int main() { //getting coffee type string friendOrder; cin >> friendOrder; printOrder(friendOrder); cout << printOrder; return 0; I appreciate any help :)
6 ответов
+ 1
Plaush You are outputting function name which doesn't make sense. The output may be any undefined value .
+ 1
Nvm, I solved it. Turns out, I was being an idiot. Solved it by placing cout ‘inside’ the function’s curly brackets. Thanks for the help! :) p
0
Hima Ahh, I see. I’ll assign it to something :)
0
Plaush The function is of type void so you can not assign it to anything .
0
Hima Hmm, you’re right. It gives me an error
0
void printOrder (string a, string b="Black_tea") {
cout << "Black tea";
}