Your task is to define the sendApology() function with the following details:
a. Return type - void
b. Function name - sendApology
c. Parameters - a character and an integer.
The sendApology() function will first check if the character passed is either 's', 'o', 'r', or 'y'. If it is, print it based on the passed integer number of times. For example, if the passed integer is 5, then you need to print the character 5 times. Otherwise, just ignore it (i.e. don't do anything).
Do not edit the main() code.
This is the given code:
#include <iostream>
using namespace std;
int main(void) {
sendApology('s', 2);
sendApology('f', 10);
sendApology('b', 3);
sendApology('o', 5);
sendApology('r', 12);
sendApology('m', 5);
sendApology('v', 2);
sendApology('y', 7);
return 0;
}
void sendApology(char letter, int n) {
// TODO: Implement the function definition
}
#include<iostream>
using namespace std;
void sendApology(char letter, int n);
int main(void)
{
sendApology('s', 2);
sendApology('f', 10);
sendApology('b', 3);
sendApology('o', 5);
sendApology('r', 12);
sendApology('m', 5);
sendApology('v', 2);
sendApology('y', 7);
return 0;
}
void sendApology(char letter, int n)
{
if (letter == 's' || letter == 'o' || letter == 'r' || letter == 'y')
{
for (int i = 0; i < n; i++)
{
cout << letter;
}
cout << endl;
}
}
Comments
Leave a comment