160k views
1 vote
Write a method printShampooInstructions(), with int parameter numCycles, and void return type. If numCycles is less than 1, print "Too few.". If more than 4, print "Too many.". Else, print "N: Lather and rinse." numCycles times, where N is the cycle number, followed by "Done.". End with a newline. Example output with input 2:

1 Answer

5 votes

Answer:

Following are the method in c language .

void printShampooInstructions(int numCycles)

{

if(numCycles<1)

{

printf(" Too few.");

}

else if(numCycles>4)

{

printf("Too many.");

}

else

{

for(int i=0;i<numCycles;++i)

{

printf("%d",i+1);

printf(" Lather and rinse\\");

}

printf("\\done");

}

}

Step-by-step explanation:

Here we create a function printShampooInstructions(int numCycles,) with integer parameter and check the following condition of numCycles variable

if numCycles < 1 control will executed the if block and print "Too few". otherwise control will move and check the condition of "else if" block If the condition of else if block will match then it executed that block Otherwise Control will moves on the else block.

Following are program in c language.

#include <stdio.h>// HEADER FILELE

void printShampooInstructions(int numCycles); // FUNCTION printShampooInstructions PROTOTYPE

int main() // MAIN METHOD

{

printShampooInstructions(3); // CALLING A FUNCTION printShampooInstructions

return 0;

}

void printShampooInstructions(int numCycles) //FUNCTION printShampooInstructions

{

if(numCycles<1)

{

printf(" Too few.");

}

else if(numCycles>4)

{

printf("Too many.");

}

else

{

for(int i=0;i<numCycles;++i)

{

printf("%d",i+1);

printf(" Lather and rinse.\\");

}

printf("\\done");

}

}

Output:

1 Lather and rinse.

2 Lather and rinse.

3 Lather and rinse.

done

User Mamrezo
by
6.2k points