- #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.
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.
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.