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 Antworten
+ 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";
}