166k views
5 votes
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 with input 2: 1: Lather and rinse. 2: Lather and rinse. Done. Hint: Declare and use a loop variable.

User Tinamarie
by
6.3k points

2 Answers

3 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 AppHandwerker
by
6.4k points
1 vote

// Writing a C++ function

void PrintShampooInstructions(int numCycles){

if(numCycles < 1) // if condition stands

cout<< "To few";

else if(numCycles >4)

cour<<"Too Many";

else{

// looping the variable for desired out put

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

cout<<i<<":"<<" Lather and rinse."<<endl;

}

}

User Sajib Mahmood
by
6.6k points