Witam! Jestem na początku mojej przygody z programowaniem. Uczę się z filmików pana Mirosława Zelenta i z książki pana Alexa Allana " C++. Przewodnik dla początkujących". Jestem przy pętlach while, for i do-while i mam do rozwiązania zadanie: Napisz program, który drukuje pełny tekst piosenki "99 Bottles of Beer".
#include <iostream>
using namespace std;
int main()
{
int x=99;
while(x>=3)
{
cout<< x << " bottles of beer on the wall, "<<x<< " bottles of beer ."<< endl;
x--;
cout<< " Take one down and pass it around, " << x <<" bottles of beer on the wall. "<<endl; //tutaj przerywam pętle
}
cout<< x <<" bottles of beer on the wall, "<< x <<" bottles of beer. "<<endl; //tutaj piszę od nowa
x--;
cout<< " Take one down and pass it around, " << x <<" bottle of beer on the wall. "<<endl; //bo tu już nie ma "bottles", tylko "bottle"
cout<< x <<" bottle of beer on the wall, "<<x<<" bottle of beer. "<<endl;
cout<<" Take one down and pass it around, no more bottles of beer on the wall. "<<endl;
{
int x =99;
cout<<"No more bottles of beer on the wall, no more bottles of beer. "<<endl;
cout<<" Go to the store and buy some more, "<<x<<" bottles of beer on the wall. "<<endl;
}
return 0;
}
1.Czy ten kod, który napisałem- w miarę nada się?
2. Mam problem ze słowem "bottles". Ogólnie chodzi o to , w piosence mamy najpierw 99 bottles, potem 98, 97. itd.. Gdy licznik tych butelek dojdzie do momentu, że została jedna butelka, to zamiast słowa "bottles"( liczba mnoga) powinno być użyte słowo "bottle"( liczba poj.). Czy da się w tej pętli jakoś tak zaktualizować to słowo, że gdy odliczanie dojdzie właśnie do tego momentu, że bottles=1, żeby zamiast "bottles" wyświetlało "bottle"? Jak widzicie , napisałem, tak jak umiałem, ale wydaje mi się, że można to zrobić jakoś prościej. Mam nadzieję, że zadałem pytanie w miarę z sensem i mi pomożecie.