PrintShampooInstructions(): Function for Looping Cycles

  • Context:
  • Thread starter Thread starter Teh
  • Start date Start date
  • Tags Tags
    Function Loop
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 6K views
Teh
Messages
47
Reaction score
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) {
      count << "Too few." << endl;
   }
   else if (numCyles > 4) {
      count << "Too many." << endl;
   }
   
   else {
          
     while (numCyles > 0) {
        count << numCyles << ": Lather and rinse."    << endl;  
        i++;
        numCyles--;

   }
   count << "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.
 
Physics news on Phys.org
Print [m]i[/m] instead of [m]numCyles[/m].