I have an assignment, where I have to count down in lyrics according to the number in user input (between 1 to 100). In the last set of lyrics, when the countdown gets to 1, it's supposed to change from bottles
to bottle
, then eventually 0.
Visual Studio is telling me I'm missing a while
(last closing bracket) and a ;
(open bracket after do (beerAmount - 1)
), but no matter where I put the ;
where I think it makes sense, it wont run. I don't understand why it's telling me I'm missing a while
statement. My professor strongly recommended I use a do-while
loop.
An example of it sucessfully running would result with an output like this:
imagine the user imputed 2
when prompted for how many bottles of beer
2 bottles of beer on the wall. 2 bottles of beer. Take 1 down, pass it around. 1 bottle of beer on the wall.
1 bottle of beer on the wall. 1 bottle of beer. Take 1 down, pass it around. 0 bottles of beer on the wall.
#include <iostream>
using namespace std;
int main()
{
int beerAmount;
int lessAmount = (beerAmount - 1);
do {
cout << "Enter an amount of beers between 0 and 101: " << endl;
cin >> beerAmount;
if ((beerAmount > 0 && beerAmount < 101)) {
break;
}
else {
cout << "Invalid amount! Please try again" << endl;
}
}
while (true); {
do (beerAmount - 1) { //this bracket
cout << beerAmount << " bottles of beer on the wall. " << beerAmount << " bottles of beer. Take " << beerAmount << " down, pass it around. " << lessAmount << " bottles of beer on the wall." << endl;
}
if ((beerAmount == 1)) {
cout << beerAmount << " bottle of beer on the wall. " << beerAmount << " bottle of beer. Take " << beerAmount << " down, pass it around. 0 bottles of beer on the wall." << endl;
}
if (beerAmount == 0) {
break;
}
} //this bracket
return 0;
}