Using string class in function

I'm trying to write a program that will output the lyrics for the song "99 Bottles of beer on the wall". It should print the number of bottles in Enlgish.
The program needs to be designed with a function that takes an argument of an integer between 0 and 99 and returns a string that contains the integer value in English. I just need some help with the function, here is the program so far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <string>
using namespace std;

string int_2_english(int num);

int main()
{
	int beers = 99;

	do{
		cout << endl << int_2_english(beers) << " Bottle" (beers > 1?"s":"") 
			 << " of beer on the wall, " << endl << int_2_english(beers)
			 << " Bottle" (beers > 1?"s":"") "of beer, \nTake one down, pass it around";

		beers--;

		while } (beers > 0);

	cout << endl << int_2_english(beers) <<" Bottle" (beers > 1?"s":"")
		 << " of beer on the wall"

	return 0;
}

string int_2_english(int num)
{
1
2
3
4
5
6
std::string toString(int num)
{
    std::stringstream ss;
    ss << num;
    return ss.str();
}


I hope it will hope, but as I see it's not exactly what do you want
Last edited on
An iterative method:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <string>
using namespace std;

string int_2_english(int num);

int main()
{
    int beers = 99;
    string str;
   
    for(beers; beers>0; beers--) {
       str = int_2_english(beers);
       cout << str << '\n';
       str.clear();
   }
   
    return 0;
}

string int_2_english(in num)
{
   string tempStr = num << "bottle's of ...";
   return tempStr;
}

Topic archived. No new replies allowed.