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>
usingnamespace std;
int bottlesofbear()
{
int x = 101;
while (x > 0) {
x -=1;
cout << x << " bottles of bears on the wall\n";
}
}
int main()
{
cout << bottlesofbear();
}
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.