Yahoo Clever wird am 4. Mai 2021 (Eastern Time, Zeitzone US-Ostküste) eingestellt. Ab dem 20. April 2021 (Eastern Time) ist die Website von Yahoo Clever nur noch im reinen Lesemodus verfügbar. Andere Yahoo Produkte oder Dienste oder Ihr Yahoo Account sind von diesen Änderungen nicht betroffen. Auf dieser Hilfeseite finden Sie weitere Informationen zur Einstellung von Yahoo Clever und dazu, wie Sie Ihre Daten herunterladen.

I need C++ Homework Help! :s?

Hey guys,

So i'm supposed to write a program that prints the song "99 bottles of root beer on the wall" using a for loop. However, it needs to be grammatically correct.

For an example:

5 bottles of root beer on the wall.

5 bottles of root beer.

Take one down, pass it around.

4 bottles of root beer on the wall.

-----------------------------------

4 bottles of root beer on the wall.

4 bottles of root beer.

Take one down, pass it around.

3 bottles of root beer on the wall.

-----------------------------------

3 bottles of root beer on the wall.

3 bottles of root beer.

Take one down, pass it around.

2 bottles of root beer on the wall.

-----------------------------------

2 bottles of root beer on the wall.

2 bottles of root beer.

Take one down, pass it around.

1 bottle of root beer on the wall.

-----------------------------------

1 bottle of root beer on the wall.

1 bottle of root beer.

Take one down, pass it around.

Need to buy some more root beer!

-----------------------------------

This is what I have so far:

#include <iostream>

using namespace std;

int main()

{

for (int i=99; i>=1; i--)

{

cout << i << " bottles of Root Beer on the wall\n";

cout << i << " bottles of Root Beer\n";

cout << "Take one down, pass it around \n";

cout << i << " bottles of Root Beer\n\n\n\n";

}

}

Can someone please help? I'm stuck and don't know what to do. Thanks.

1 Antwort

Relevanz
  • ?
    Lv 7
    vor 5 Jahren
    Beste Antwort

    #include <iostream>

    using namespace std;

    int main()

    {

    for (int i=3; i>=0; i--) {

    cout << i << " bottle"<<((i==1)?"":"s" )<<" of Root Beer on the wall\n";

    cout << i << " bottle"<<((i==1)?"":"s" )<<" of Root Beer\n";

    cout << "Take one down, pass it around \n";

    cout << i << " bottle"<<((i==1)?"":"s" )<<" of Root Beer\n\n\n\n";

    }

    return 0;

    }

Haben Sie noch Fragen? Jetzt beantworten lassen.