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.

Respuesta :

// 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;

}

}

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.");

    }

  }

Explanation:

Ver imagen DarthVaderBarbie