0

44.2 Practice: More Megabytes Please!

You operate a mobile provider running a promotion that multiplies a user's internet bandwidth. Fix the program by completing the function and calling it, so that the given megabyte outputs before and after the promotion work correctly. The multiplier is taken as input inside the multiplier function. Sample Input 5 2 Sample Output Before the promotion: 5 After the promotion: 10 *Use address-of operator & in function call. My code as below and I have tried a few hours but I can’t figure it out.

15th Dec 2021, 1:24 AM
Chin Eu
Chin Eu - avatar
3 odpowiedzi
+ 1
#include <iostream> using namespace std; /*complete the function to multiple the megabytes, don't forget to set the parameter*/ void promotion(int *x) { //taking multiplier as input int multiplier; cin>>multiplier; *x *=multiplier; } int main() { //getting initial count of megabytes int megabytes; cin >> megabytes; //printing the count of megabytes before the promotion cout << "Before the promotion: " << megabytes << endl; //complete the function call promotion(&megabytes); //printing the count of megabytes after the promotion cout << "After the promotion: " << megabytes << endl; return 0; }
9th Jan 2022, 1:40 AM
Saul Diaz
Saul Diaz - avatar
0
#include <iostream> using namespace std; /*complete the function to multiple the megabytes, don't forget to set the parameter*/ void promotion(int *x) { *x = 2; //taking multiplier as input int multiplier; cin>>multiplier; } int main() { int var = 2; //getting initial count of megabytes int megabytes; cin >> megabytes; //printing the count of megabytes before the promotion cout << "Before the promotion: " << megabytes << endl; //complete the function call promotion(&var); //printing the count of megabytes after the promotion cout << "After the promotion: " << megabytes << endl; return 0; }
15th Dec 2021, 1:24 AM
Chin Eu
Chin Eu - avatar
0
Thanks Saul Diaz !
9th Jan 2022, 10:14 PM
Chin Eu
Chin Eu - avatar