My function is messed up slightly

my program was just to test a function about the song "99 bottles of bear on the wall" which runs correctly but at the end when it says "0 bottles of bear on the wall" there is a new line with a 0 at the end for some reason
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
using namespace std;

int bottlesofbear()
{
   int x = 101;
    while (x > 0) {
    x -=1;
   cout << x << " bottles of bears on the wall\n";
    }
}


int main()
{

    cout << bottlesofbear();
}
Last edited on
bottlesofbear returns an int, which will by default be 0.
You call cout << bottlesofbear();, so the function will do all of its output, then return the value 0, which is also output through cout.

1
2
3
4
5
int main()
{
    bottlesofbear();
    return 0;
}

The above will fix that.
Thanks I appreciate it and I just started learning functions so I don't fully understand it yet
Also, it's "beer", not "bear" ;)
Oh yeah I just noticed lol thanks
Topic archived. No new replies allowed.