Witam, mam do zrobienia zdanie, które polega na wyświetleniu w pętli tekstu piosenki. Zaczynając od 99, lub liczby podanej jako argument w wierszu poleceń, porgram ma wypisać:
99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.
Po osiągnięciu 0 ma wypisać:
No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.
Z wypisaniem tekstu piosenki przez pętle po prostu zaczynając od 99 nie miałem problemu, lecz nie wiem co zrobić, aby kod zadział przy ewentualności podania argumentu przez użytkownika. Oto mój kod:
#include <iostream>
#include <string>
auto main(int argc, char* argv[])->int
{
auto liczba = std::stoi(argv[1]);
if(argc==0)
{
for(auto i=99; i>=0; i--)
{
if(i==0)
{
std::cout<<"No more bottles of beer on the wall, no more bottles of beer."<<"\n"<<"Go to the store and buy some more, 99 bottles of beer on the wall..."<<"\n";
}
else if(i==2)
{
std::cout<<i<<" bottles of beer on the wall, "<<i<<" bottles of beer."<<"\n"<<"Take one down, pass it around, "<<i-1<<" bottle of beer on the wall..."<<"\n";
}
else if(i==1)
{
std::cout<<i<<" bottle of beer on the wall, "<<i<<" bottle of beer."<<"\n"<<"Take one down, pass it around, no more bottles of beer on the wall..."<<"\n";
}
else
{
std::cout<<i<<" bottles of beer on the wall, "<<i<<" bottles of beer."<<"\n"<<"Take one down, pass it around, "<<i-1<<" bottles of beer on the wall..."<<"\n";
}
}
}
else if(argc==1)
{
for(auto i=liczba; i>=0; i--)
{
if(i==0)
{
std::cout<<"No more bottles of beer on the wall, no more bottles of beer."<<"\n"<<"Go to the store and buy some more, 99 bottles of beer on the wall..."<<"\n";
}
else if(i==2)
{
std::cout<<i<<" bottles of beer on the wall, "<<i<<" bottles of beer."<<"\n"<<"Take one down, pass it around, "<<i-1<<" bottle of beer on the wall..."<<"\n";
}
else if(i==1)
{
std::cout<<i<<" bottle of beer on the wall, "<<i<<" bottle of beer."<<"\n"<<"Take one down, pass it around, no more bottles of beer on the wall..."<<"\n";
}
else
{
std::cout<<i<<" bottles of beer on the wall, "<<i<<" bottles of beer."<<"\n"<<"Take one down, pass it around, "<<i-1<<" bottles of beer on the wall..."<<"\n";
}
}
}
else
{
std::cout<<"Podales niewlasciwe argumenty"<<"\n";
}
return 0;
}
Byłbym bardzo wdzięczny, gdyby ktoś mi pomógł, lub nakierował. Z góry dzięki!