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
}
#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;
}
Comments
Leave a comment