Question

C++ Help!    For this lab, we are going to practice a few different aspects of...

C++ Help!   

For this lab, we are going to practice a few different aspects of programming in C++.

·        Practice using cin and cout.

·        Practice using a loop (for or while)

·        Practice using a c-string.

For this lab, you are going to create the code that writes the lyrics for the old song, “99 Bottles of Beer” with a slight change. If you have never seen the song, you can view the lyrics here: http://www.99-bottles-of-beer.net/lyrics.html

Our version will be very similar, except, we are going to allow the user to decide what number to start at and what type of bottle we are passing around.

-bash-4.1$ ./lab1

What number would you like to start with?:

3

What type of bottle would you like?:

soda

3 bottles of soda on the wall.

3 bottles of soda.

Take one down, pass it around.

2 bottles of soda on the wall.

2 bottles of soda on the wall.

2 bottles of soda.

Take one down, pass it around.

1 bottles of soda on the wall.

1 bottles of soda on the wall.

1 bottles of soda.

Take one down, pass it around.

No bottles of soda on the wall.

-bash-4.1$

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// C++ code

#include <iostream>
#include <fstream>
#include <cctype>
#include <cstring>
#include <iomanip>
using namespace std;

int main()
{
int bottles;
string type;
  
cout << "What number would you like to start with?: ";
cin >> bottles;

cout << "What type of bottle would you like?: ";
cin >> type;

cout << bottles << " bottles of soda on the wall. " << endl;
cout << bottles << " bottles of soda." << endl;

while(bottles--)
{
cout << "Take one down, pass it around." << endl;
if (bottles == 0)
{
cout << "No bottles of soda on the wall." << endl;
break;
}
cout << bottles << " bottles of soda on the wall." << endl;
cout << bottles << " bottles of soda on the wall." << endl;
cout << bottles << " bottles of soda." << endl;
}
return 0;
}

/*
output:

What number would you like to start with?: 7
What type of bottle would you like?: beer
7 bottles of soda on the wall.
7 bottles of soda.
Take one down, pass it around.
6 bottles of soda on the wall.
6 bottles of soda on the wall.
6 bottles of soda.
Take one down, pass it around.
5 bottles of soda on the wall.
5 bottles of soda on the wall.
5 bottles of soda.
Take one down, pass it around.
4 bottles of soda on the wall.
4 bottles of soda on the wall.
4 bottles of soda.
Take one down, pass it around.
3 bottles of soda on the wall.
3 bottles of soda on the wall.
3 bottles of soda.
Take one down, pass it around.
2 bottles of soda on the wall.
2 bottles of soda on the wall.
2 bottles of soda.
Take one down, pass it around.
1 bottles of soda on the wall.
1 bottles of soda on the wall.
1 bottles of soda.
Take one down, pass it around.
No bottles of soda on the wall.


*/

Add a comment
Know the answer?
Add Answer to:
C++ Help!    For this lab, we are going to practice a few different aspects of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (Python) 3. 99 Bottles of Beer on the Wall song, recursively Write a function Recurse that...

    (Python) 3. 99 Bottles of Beer on the Wall song, recursively Write a function Recurse that prints out the verses of the famous song, Lyrics of the song 99 Bottles of Beer (shown below). You must called this function recursively. 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. 98 bottles of beer on the wall, 98 bottles of beer. Take one down and...

  • Java hw Write a program that outputs the lyrics for “Ninety-nine Bottles of Beer on the...

    Java hw Write a program that outputs the lyrics for “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, Ninety-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...

  • Problem 1 Write a program that outputs the lyrics for “Ninety-nine Bottles of Beer on the...

    Problem 1 Write a program that outputs the lyrics for “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, Ninety-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...

  • LAB PROMPT: Lab 06 For this lab you are going to practice writing method signatures, implementing...

    LAB PROMPT: Lab 06 For this lab you are going to practice writing method signatures, implementing if statements, and improve your skills with for loops. The methods you will be writing have nothing to do with each other but allow you to use the skills you have gained so far to solve a series of small problems. Power For this method you will practice using methods from the Math class. The first step you must take is to write the...

  • We are going to create a few different classes in this project. I will supply one...

    We are going to create a few different classes in this project. I will supply one of the classes: Pound (as in a pound for animals). Your goal will be to create proper Dog and Cat classes that will work in conjunction with this Pound class. Before starting to the design process for the Dog/Cat classes, carefully inspect this code. Get an idea of the goal of the Cat/Dog classes. How many fields will they store? What will the constructors...

  • C SHARP PROGRAM LANGUAGE The program below isn't working quite right. First compile and run it...

    C SHARP PROGRAM LANGUAGE The program below isn't working quite right. First compile and run it to familiarize yourself with the output. Then update the program to implement the following requirements: 1. the program shall sing ( display with WriteLine() ) the song's verses for drinks 100 through 91. 2. the program shall not sing the song's verses for drinks 90 - 7. 3. the program shall implement a string variable which is initialized by the programmer to the type...

  • This lab illustrates how supersaturated solutions are prepared, and the process of crystallization. This lab can...

    This lab illustrates how supersaturated solutions are prepared, and the process of crystallization. This lab can be done with a number of different salts. You will need to allow your solutions to sit for at least three weeks. This is one way to make rock candy. Be SURE to start this lab with plenty of time to finish. Materials -string -pencils -glass drink bottles -various salts (choose from the following list.) -table salt, sodium chloride -alum -baking soda -copper sulfate...

  • Lab 11- One-way-ANOVA-Balanced Worksheet 1) For this lab practice, we are going to use the exercise...

    Lab 11- One-way-ANOVA-Balanced Worksheet 1) For this lab practice, we are going to use the exercise done in elass. Compare your result from the Minitab output to the results obtained in class doing the calculations by hand. Example: A firm wishes to compare four programs for training workers to perform a certain manual task. Twenty new employees are randomly assigned to the training programs,w each program. At the end of the training period, can perform the task. with 5 in...

  • Background In this lab, we are going to learn how to use a powerful separation technique...

    Background In this lab, we are going to learn how to use a powerful separation technique called chromatography which can separate compounds that are quite similar to one another. Chromatography is a general type of separation in which a mixture of compounds passes through a stationary phase. Different compounds have different relative affinities for the mixture traveling along the stationary phase, or the mobile phase, and the stationary phase, causing these compounds to separate from one another. More specifically, we’re...

  • In this lab we are going to complete a profile of two sorting algorithms by running...

    In this lab we are going to complete a profile of two sorting algorithms by running some tests to collect empirical data. 1. First we need to be able to generate some random integers. You can do this by including the following library : #include Now first run the following to generate a seed : srand (time(NULL)) You can then generate a random number using the function rand() 2. We will use two sort algorithms - Selection Sort and Bubble...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT