132k views
1 vote
Write a function 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 for numCycles = 2: 1: Lather and rinse. 2: Lather and rinse. Done. Hint: Declare and use a loop variable.

User Rella
by
5.2k points

2 Answers

3 votes

Well, you didn't say what language, so here's in Java:


public static void PrintShampooInstructions(int numCycles)

{

if(numCycles < 1)

System.out.println("Too few.");

else if (numCycles > 4)

System.out.println("Too many.");

else

{

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

{

System.out.println(i+": Lather and rinse.");

}

System.out.println("Done.");

}

}


And also in an image, in case you can't really see it

Write a function PrintShampooInstructions(), with int parameter numCycles, and void-example-1
User AhMaD AbUIeSa
by
4.9k points
4 votes

Answer:

public static void printShampooInstructions(int numOfCycles){

if(numOfCycles < 1){

System.out.println("Too few.");

}

else if(numOfCycles > 4){

System.out.println("Too many.");

}

else {

for(int index = 0; index < numOfCycles; ++index){

System.out.println((index + 1) + ": Lather and rinse.");

}

System.out.println("Done.");

}

}

Step-by-step explanation:

Write a function PrintShampooInstructions(), with int parameter numCycles, and void-example-1
User Irshad
by
5.4k points