Question: Copy the program from Assignment 1 and name it Assignment 2. This assignment is intended to have the same output as Assignment 1. Continue to

Copy the program from Assignment 1 and name it Assignment 2.

This assignment is intended to have the same output as Assignment 1.

Continue to do your loop in the main method. Create a new bool method that will generate the console output. You must pass the X number of beers to the method and call this method inside your loop. The main() method should not have any display work as the cout tasks should have been moved to the new bool method.

This new method must return true when passed a number equal to 2 or higher. This method must return false if the passed value is less than 2.

The loop must run as long as the returned value of the method is true.

HINT: If you were using a "FOR" loop for assignments 1, you may want to consider another looping construct.

Review Chapter 6 - Functions and Value-Returning Functions.

Deliverable for assignment 2 is your C program only.

Assignment 1:

#include

using namespace std; //main method

int main() {

//initialize bottles variables bot as 0

int bot = 0;

//loop will iterate till the valid input given

while (bot <= 0 || bot >= 101)

{

cout << "Enter initial number of bottles > ";

cin >> bot;

}

//loop function will iterate until bottles on the wall 0

for (int i = bot; i > 0; i--)

{

//this is where we check the number of bottles is 1

// and then we print bottle otherwise bottles

if (i == 1) {

cout << i << " bottle of beer on the wall. ";

cout << i << " bottle of beer. Take 1 down, pass it around.";

}

else {

cout << i << " bottles of beer on the wall. ";

cout << i << " bottles of beer. Take 1 down, pass it around.";

}

if (i - 1 == 1)

cout << i - 1 << " bottle of beer on the wall.";

else

cout << i - 1 << " bottles of beer on the wall.";

cout << endl;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!