18.9k views
0 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.

So, this is what I have done.
#include
using namespace std;
void PrintShampooInstructions( int numCycles ) {
if (numCycles < 1) {
cout << "Too few." << endl ;
}
if (numCycles > 4 ) {
cout << "Too many." << endl ;
}
else {
int i = 0 ;
int N = 0 ;
for ( i = N ; i < numCycles ; ++i) {
cout << "i: Lather and rinse." << endl ;
cout << "Done." << endl ;
}
}
}
return ;
}
int main() {
PrintShampooInstructions(2);

return 0;
}

User Vianey
by
5.2k points

1 Answer

5 votes

Answer:

See explaination

Step-by-step explanation:

Source code below.

#include <iostream>

using namespace std;

// <STUDENT CODE>

// Define the function PrintShampooInstructions().

void PrintShampooInstructions(int numCycles)

{

// Display "Too few." if the value

// of numCycles is less than 1.

if (numCycles < 1)

{

cout << "Too few." << endl;

}

// Display "Too many." if the value

// of numCycles is greater than 4.

else if (numCycles > 4)

{

cout << "Too many." << endl;

}

// Otherwise, do the following:

else

{

// Define the loop variable.

int N = 1;

// Start the loop from 1 to numCycles.

for (N = 1; N <= numCycles; N++)

{

// Print the value of N followed by "Lather and rinse".

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

}

// Print "Done." followed by newline.

cout << "Done." << endl;

}

}

// Define the main() function.

int main()

{

PrintShampooInstructions(2);

return 0;

}

Please kindly check attachment for sample output and program screen shot.

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