Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i need help with this problem in c++ Write a program that outputs the lyrics for

ID: 3632802 • Letter: I

Question

i need help with this problem in c++

Write a program that outputs the lyrics for the song “Ninety-Nine Bottles of Beer on the Wall.” Your program should print the number of bottles in English, not as a number. For example,
Ninety-nine bottles of beer on the wall,
Nine-nine bottles of beer,
Take one down, pass it around,
Ninety-eight bottles of beer on the wall.

One bottle of beer on the wall,
One bottle of beer,
Take one down, pass it around,
Zero bottles of beer on the wall.

Design your program with a function that takes an argument an integer between 0 and 99 and returns a string that contains the integer value in English. Your function should not have 100 different if-else statements! Instead use % and / to extract tens and ones digits to construct the English string. The user should input the integer from the keyboard.

Explanation / Answer

please rate - thanks


#include <iostream>
#include <cstring>
using namespace std;
string number(int);
void lyric(int num);
int main()
{int num;
do{
cout<<"What number do you want to start with: ";
   cin>>num;
   if(num<0||num>99)
      cout<<"Invalid entry ";
}while(num<0||num>99);
cout<<endl;
while(num>0)
   {lyric(num);
   num--;
}
system("pause");
return 0;
}
string number(int num)
{int tens,ones;
string word="";
switch(num)
{
case 10: return("Ten ");
case 11: return("Eleven ");
case 12: return("Twelve ");
case 13: return("Thirteen ");
case 14: return("Fourteen ");
case 15: return("Fifteen ");
case 16: return("Sixteen ");
case 17: return("Seventeen ");
case 18: return("Eighteen ");
case 19: return("Nineteen ");
case 0: return("Zero ");
}
tens=num/10;
> switch(tens)
{case 9: word="Ninety-"; break;
case 8: word="Eighty-";break;
case 7: word="Seventy-"; break;
case 6: word="Sixty-"; break;
case 5: word="Fifty-";break;
case 4: word="Forty-";break;
case 3: word="Thirty-";break;
case 2:word="Twenty-";break;
}
switch(ones)
{case 1: word+="One "; break;
case 2: word+="Two "; break;
case 3: word+="Three "; break;
case 4: word+="Four "; break;
case 5: word+="Five "; break;
case 6: word+="Six "; break;
case 7: word+="Seven ";break;
case 8: word+="Eight ";break;
case 9: word+="Nine "; break;
}
return word;
}
void lyric(int num)
{
string word;
word=number(num);
cout<<word;
if(num==1)
      cout<<"bottle of beer on the wall,"<<endl;
else
      cout<<"bottles of beer on the wall, "<<endl;
cout<< word;
if(num==1)
    cout<<"bottle of beer, "<<endl;
else
    cout<<"bottles of beer, "<<endl;
cout<<"Take one down, pass it around,"<<endl;

      num--;
      word=number(num);
      cout<<word;
      if(num==1)
          cout<<"bottles of beer on the wall, "<<endl<<endl;
      else
          cout<<"bottles of beer on the wall, "<<endl<<endl;

return;
}