[try Beta version]
Not logged in

 
99 bottles of beer on the wall, help..

Nov 12, 2015 at 12:41am
Working on an assignment to allow a user to input the number of beers they have left on the wall, and the program will finish the lyrics.
I've made it work, however, my professor wants it to display "No more beers on the wall" when it reaches 0, instead of actually saying 0 beers on the wall.
My current code shows " No more beers on the wall" at the end, however, it still displays the 0.. and I can't make the 0 disappear. Any help? thank you very much.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
    {
    int bottles;
    int noBottles = 0;
    cout << "Please enter the number of beers on the Wall between 1 - 99. " << endl;
    cin >> bottles;
    while( bottles > 99 || bottles < noBottles)
   {
   	cout << "Invalid Response. Please enter a number of beers between 1-99 " << endl;
   	cin >> bottles;
   }
	while ( bottles > noBottles )
        {
        cout << bottles << " bottle(s) of beer on the wall," << endl;
        cout << bottles << " bottle(s) of beer." << endl;
        cout << "Take one down, pass it around," << endl;
        cout << --bottles << endl;
           if (bottles == noBottles)
           {
		   cout << "No more bottles of beer on the wall" << endl;
	       }
	       else 
	       {
		   cout << " bottle(s) of beer on the wall." << endl;
           }
		}
        
    
        
    return 0;
    }
Nov 12, 2015 at 1:22am
just put an if statement around the cout bottles

1
2
if (bottles != 1 )
	cout << --bottles << endl;


*Edit . sry i had to change it

you need to increment the bottles separately from the operation(or continuous loop)

bottles--;
if (bottles != 0)
cout << bottles << endl;
Last edited on Nov 12, 2015 at 1:31am
Topic archived. No new replies allowed.