174k views
3 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 for numCycles = 2:

1: Lather and rinse.
2: Lather and rinse.
Done.
Hint: Define and use a loop variable.
Sample program:
#include
using namespace std;

int main() {
PrintShampooInstructions(2);
return 0;
}

User Glessard
by
4.4k points

2 Answers

5 votes

Answer:

#In Python

def shampoo_instructions(num_cycles):

if num_cycles < 1: ///

print ('Too few.') ///

elif num_cycles > 4:

print ('Too many.')

else:

i = 0

while i<num_cycles:

print (i+1,": Lather and rinse.")

i = i + 1

print('Done.')

user_cycles = int(input())

shampoo_instructions(user_cycles)

Step-by-step explanation:

def shampoo_instructions(num_cycles): #def function with loop

if num_cycles < 1: #using 1st if statement

print('Too few.')

elif num_cycles > 4:

print ('Too many.')

else:

i = 0

while i<num_cycles:

print (i+1,": Lather and rinse.")

i = i + 1

print('Done.')

user_cycles = int(input())

shampoo_instructions(user_cycles)

User Oladapo Omonayajo
by
6.1k points
3 votes

Answer:

public static void PrintShampooInstructions(int numberOfCycles){

if (numberOfCycles<1){

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

}

else if(numberOfCycles>4){

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

}

else

for(int i = 1; i<=numberOfCycles; i++){

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

}

System.out.println("Done");

}

Step-by-step explanation:

I have used Java Programming language to solve this

Use if...elseif and else statement to determine and print "Too Few" or "Too Many".

If within range use a for loop to print the number of times

User Dhiral Kaniya
by
4.7k points