PrintShampooInstructions(): Function for Looping Cycles

In summary, the function PrintShampooInstructions() takes in an integer parameter called numCycles and has a void return type. If numCycles is less than 1, it will print "Too few." If it is more than 4, it will print "Too many." Otherwise, it will print "N: Lather and rinse." numCycles times, where N is the cycle number, followed by "Done." and end with a newline. For example, if numCycles is 2, the output will be: 1: Lather and rinse. 2: Lather and rinse. Done.
  • #1
Teh
47
0
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.



HTML:
#include <iostream>
using namespace std;

/* Your solution goes here  */
void PrintShampooInstructions(int numCyles) {
   int i = 1;
   if (numCyles < 1) {
      cout << "Too few." << endl;
   }
   else if (numCyles > 4) {
      cout << "Too many." << endl;
   }
   
   else {
          
     while (numCyles > 0) {
        cout << numCyles << ": Lather and rinse."    << endl;  
        i++;
        numCyles--;

   }
   cout << "Done." << endl;
   }
   return;
}int main() {
   PrintShampooInstructions(2);

   return 0;
}

Testing with 0Your output:
Too few.


Testing with 2



Expected output:
1: Lather and rinse.
2: Lather and rinse.
Done.



Your output:
2: Lather and rinse.
1: Lather and rinse.
Done.



Tests aborted.


Cant figure out how to change this:

2: Lather and rinse.
1: Lather and rinse.
Done.


Into:

1: Lather and rinse.
2: Lather and rinse.
Done.
 
Technology news on Phys.org
  • #2
Print [m]i[/m] instead of [m]numCyles[/m].
 

FAQ: PrintShampooInstructions(): Function for Looping Cycles

What is the purpose of the PrintShampooInstructions() function?

The PrintShampooInstructions() function is used to print out instructions for a shampooing cycle. It can be used in a loop to repeat the instructions for multiple cycles.

How does the PrintShampooInstructions() function work?

The function works by using a loop to repeat the instructions for each cycle. It takes in parameters such as the number of cycles and the type of shampoo to be used, and prints out the appropriate instructions for each cycle.

What are the parameters for the PrintShampooInstructions() function?

The PrintShampooInstructions() function takes in two parameters: the number of cycles and the type of shampoo. The number of cycles parameter specifies how many times the instructions should be repeated, while the type of shampoo parameter specifies the type of shampoo to be used.

Can the PrintShampooInstructions() function be used for different types of shampoo?

Yes, the function can be used for different types of shampoo. The type of shampoo is a parameter that can be specified when calling the function, allowing for flexibility in the instructions printed for each cycle.

How can the PrintShampooInstructions() function be used in a larger program?

The PrintShampooInstructions() function can be used within a larger program by calling it within a loop or using it as part of a larger function. It can also be incorporated into a user interface, allowing for customizable options such as the number of cycles and type of shampoo to be selected by the user.

Similar threads

Replies
1
Views
6K
Replies
5
Views
2K
Replies
5
Views
4K
Replies
5
Views
2K
Replies
23
Views
2K
Back
Top