Answer to Question #320807 in C++ for Magisk

Question #320807

In the code editor, you are provided with a main() function that asks for an integer input from the user which represents the cash to be given to Lionel and passes it to the getGift() function call.



The getGift() function is already declared and partially defined. Your task is to complete the function definition.



The getGift() function multiplies the passed integer value by 3 and then checks if the result is even. If it is, the getGift() function adds 100 to the result. Otherwise, it adds 200 to the result.



The getGift() function would then return the result as the return type of this function is int.



Given code:



#include <iostream>


using namespace std;



int getGift(int);



int main(void) {


int cash;



cout << "Enter cash amount: ";


cin >> cash;



int result = getGift(cash);



cout << "I'm giving you P" << result;




return 0;


}



int getGift(int cash) {


// TODO: Implement the function definition



}

1
Expert's answer
2022-03-30T07:39:40-0400
#include<iostream>

using namespace std;

int getGift(int);

int main(void)
{
	int cash;
	cout << "Enter cash amount: ";
	cin >> cash;
	int result = getGift(cash);
	cout << "I'm giving you P" << result;
}

int getGift(int cash)
{
	cash *= 3;
	if (cash % 2 == 0)
	{
		cash += 100;
	}
	else
	{
		cash += 200;
	}
	return cash;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog