+ 1

Function with no return with parameters and default Arguments

This question is from Udemy, the question is to print a grocery list where you buy apples = 13 Mangoes = 3 and Oranges = 7 Can anyone code this out to me and explain it?

28th Nov 2019, 2:08 PM
Dipanjan Basu
Dipanjan Basu - avatar
6 Respuestas
+ 3
According to your requirement you can declare and initialize those variables inside the function itself and then print each of them. Then you can call the function in your main method just with its name. You don't need a return but a return type void to do the above.
28th Nov 2019, 2:19 PM
Avinesh
Avinesh - avatar
+ 2
Post the link of your code with errors and we will help. We don't write the whole code unless you show us what you have tried.
28th Nov 2019, 2:41 PM
Avinesh
Avinesh - avatar
+ 2
Learn about functions or if you already know then kindly revisit it. Now here you go. https://code.sololearn.com/cRH4VKEQRw4b/?ref=app
28th Nov 2019, 3:07 PM
Avinesh
Avinesh - avatar
+ 1
#include <iostream> using namespace std; void grocery_list (int apple = 12, int mango = 3,int oranges = 7); int main () { grocery list (); return 0; } void (int apple, int mango, int oranges) { cout<< "Apple is:"; cout<< "Oranges is:"; cout<< "Mangoes is:" }
28th Nov 2019, 2:58 PM
Dipanjan Basu
Dipanjan Basu - avatar
0
Bro it would have been better if you could just code it out I am getting errors!
28th Nov 2019, 2:39 PM
Dipanjan Basu
Dipanjan Basu - avatar
0
There you go.
28th Nov 2019, 2:58 PM
Dipanjan Basu
Dipanjan Basu - avatar