99 Bottles of Beer starts at 74?

I was doing one of the practice problems but when i run the program and choose the 99 bottles of beer, it begins to count down from 74 rather than the 99.
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <math.h>

using namespace std;

int bottles();

int calc ();

int main()
{
    int choice;

    const int Opt1 = 1;
    const int Opt2 = 2;
    cout << "1. 99 Bottles of Beer Lyrics" << '\n' << "2. Addition Calculator" << endl;
    cout << "the lyrics or calculator? ";
    cin >> choice;

    switch (choice){
    case Opt1:
        bottles();
        break;
    case Opt2:
        calc();
        break;
    }
        return(0);
}

int bottles(){
    int bot = 99;
    while ( bot > 0 )
        {
        cout << bot << " bottle(s) of beer on the wall," << endl;
        cout << bot << " bottle(s) of beer." << endl;
        cout << "Take one down, pass it around," << endl;
        cout << --bot << " bottle(s) of beer on the wall." << endl;
        }
    }

 int calc (){
    int x,y;
    cout << "x: ";
    cin >> x;
    cout << "y: ";
    cin >> y;
    cout << x << "+" << y << "=" << x+y;
    return 0;
    }
Are you sure the text of the lines from 99 to 75 are not 'gone' in the console? If too much text is written in the console, it'll display the last lines only. Try adding a cin.get() to see what appears every time one loop is completed!
How does this program even compile? Your "int bottles" function doesnt return anything.
closed account (SECMoG1T)
I agree with @Basv the output can't fit on the console size , @TarikNeaj it should compile even if you din't return anything though that will remain an error when using such functions
Last edited on
@Andy1992 sure as hell doesnt let me compile. Visual studios 2013.

Edit: Also, you shouldnt use int function if you're not gonna return anything. You want to use void in that case.
Last edited on
@TarikNeaj

Because there is nothing wrong with the code, see below.

@andy1992

It is undefined behaviour, not an error. What will happen is that when the function reaches the end, the function will return whatever value is in the return register ( Probably EAX ).

@OP

To test the output theory, output the bottles function to a file.
It is undefined behaviour, not an error
Undefined behavior is allowed to cause compile-time error.
the function will return whatever value is in the return register
Or 0. Or something else. It is also unknown if it will cause stack pointer to change. I am being pedantic here, but expecting some concrete results is worse than allowing such situation to happen.

To test the output theory, output the bottles function to a file.
To add to that: On Windows you can redirect output to file without modifying code by calling your program as program.exe > output.txt
Topic archived. No new replies allowed.