Response:
Function 1:
#include <stdio.h> //import input-output functionality
// this begins the function PrintPopcornTime body, accepting an integer variable //bagOunces as a parameter
void PrintPopcornTime(int bagOunces){
if (bagOunces < 3){ //check if bagOunces equals less than 3
printf("Too small"); //outputs Too small message
printf("\n"); } //prints a new line//The next else if executes when prior conditions are false and bagOunces surpasses 10
else if (bagOunces > 10){
printf("Too large"); //outputs the message: Too large printf("\n");
//prints a new line
}/*else will run when bagOunces is nether under 3 nor over 10 */
else {
/* The subsequent three statements could store bagOunces * 6 in result for printing. However, you can simply use one print statement printf("%d",bagOunces * 6) instead */
//int result;
//result = bagOunces * 6;
//printf("%d",result);
printf("%d",bagOunces * 6); /calculates the value of bagOunces multiplied by 6
printf(" seconds"); // "seconds" follows the value of bagOunces * 6
printf("\n"); }}
//outputs a new line
int main(){
//initiating main function body
int userOunces; //defines integer variable userOunces
scanf("%d", &userOunces); //captures userOunces input
PrintPopcornTime(userOunces);
//calls PrintPopcornTime function with userOunces argument
return 0; }
Function 2:
#include <stdio.h>
//header for using input-output functions// this starts the function PrintShampooInstructions body with integer variable numCycles as
a parametervoid PrintShampooInstructions(int numCycles){
if(numCycles < 1){
//checks if numCycles is below 1 or not
printf("Too few.");
//outputs Too few if the condition is metprintf("\n"); }
//prints a new line
//else if executes when the condition fails, checking if numCycles exceeds 4
else if(numCycles > 4){
//outputs Too many if the above condition is accepted
printf("Too many.");
printf("\n"); } //prints a new line//else will handle when previous if and else if evaluations return false
else{
//outputs "N: Lather and rinse." numCycles times, with N presenting the cycle //number, finished with Done
for(int N = 1; N <= numCycles; N++){
printf("%d",N);
printf(": Lather and rinse. \n");}
printf("Done.");
printf("\n");} }
int main()
//start of the main function body
{ int userCycles;
//defines integer variable userCycles
scanf("%d", &userCycles); //receives input for userCycles
PrintShampooInstructions(userCycles); //executes the PrintShampooInstructions function with userCycles argument
return 0;}
I will clarify the for loop present in PrintShampooInstructions() function. The loop initializes variable N to 1 and evaluates if N remains lesser than or equal to numCycles.
Suppose numCycles = 2. The condition holds true since N < numCycles confirming 1 < 2, thus entering the loop's body. Following statements appear:
printf("%d",N); outputs the value of N followed by printf(": Lather and rinse. \n"); which will print Lather and rinse along with a newline \n.
Initially, this line emerges on the screen as:
1: Lather and rinse.After which, N is enhanced by 1 making it 2 (i.e. N = 2).[TAG_191] During the second iteration:
The loop assesses if N remains below or equal to numCycles. We know numCycles = 2. As the condition is satisfied, the flow of control commences into the loop’s body.
printf("Done."); articulates Done after the preceding two lines are printed.Now, the subsequent check leads to if N remains lower than or equal to numCycles. Noticing that N now reads 3 or greater than 2 thus terminating the loop. The result is:
printf("Done.");
displays Done on the screen.
The collective output is visualized as:1: Lather and rinse.2: Lather and rinse.
Done.
The accompanying programs with their outputs are attached.