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.
3 Respostas
+ 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;
}
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;
}
0
Thanks Saul Diaz !