Question

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 of drink to sing about e.g. beer, soda, tea, water.

4. the program shall not hard code the drink type when displaying.

5. the program shall use the string variable defined in requirement #3 above when displaying the drink type.

6. the program shall display a message like "Well, at least I have 6 cans of ?? left" and break out of the enclosing loop when only 6 drinks are left.

using System;
using static System.Console;
class song
{
    static void Main()
    {
        for (int cans = 100; cans > 0; cans--)
        {
            if (cans <= 90 && cans >= 6)
                continue;

            Write($"{cans} cans of beer on the wall ");
            Write($"{cans} cans of beer. Take one down, pass it around ");
            WriteLine($"{cans - 1} cans of beer on the wall.");

            if (cans == 6)
                break;
        }
        ReadLine();
    }
}

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

modified code:

using System;
using static System.Console;
class song
{
static void Main()
{
WriteLine("Enter type of drink:");
string drinktype;
WriteLine("For Example:");
WriteLine("beer soda tea water ");
//Taking drink type as input.
drinktype=ReadLine();
for (int cans = 100; cans > 0; cans--)
{
//The condition ignores cans from 7 to 90
if (cans <= 90 && cans > 6)
continue;
//Condition stops loop when can value reached to 6 and display message.
if (cans == 6)
{
WriteLine("Well, at least I have 6 cans of "+drinktype+" left");
break;
}
//we have used to print the name of the drink where the drink type is specified.
Write($"{cans} cans of "+drinktype);
Write($" {cans} cans of "+drinktype+". Take one down, pass it around ");
WriteLine($"{cans - 1} cans of "+drinktype+" on the wall.");   
}
//ReadLine();
//It is unnecessary
}
}

Screenshots:

using System; using static System.Console; class song static void Main() WriteLine(Enter type of drink:); string drinktype;

output:

Enter type of drink: For Example beer soda tea water water 100 cans of water 1e0 cans of water. Take one down, pass it around

If you have any queries, please comment below.

Please upvote , if you like this answer.

Add a comment
Know the answer?
Add Answer to:
C SHARP PROGRAM LANGUAGE The program below isn't working quite right. First compile and run it...
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
  • Instructions CheckZips.cs + >_ Terminal Write a program named CheckZips that is used by a package...

    Instructions CheckZips.cs + >_ Terminal Write a program named CheckZips that is used by a package delivery service to check delivery areas. 1 using static System.Console; 2 class CheckZips 3 { 4 static void Main() 5 { 6 string[] zips = {"12789", "54012", "54481", "54982", "60007", "60103", "60187", "60188", "71244", "90210"}; CheckZips.cs(10,8): error CS002 9: Cannot implicitly convert ty pe 'string' to 'string[]' CheckZips.cs(18,5): error CS001 9: Operator '==' cannot be appl ied to operands of type 'string []' and...

  • Overview JAVA LANGUAGE PROBLEM: The owner of a restaurant wants a program to manage online orders...

    Overview JAVA LANGUAGE PROBLEM: The owner of a restaurant wants a program to manage online orders that come in. This program will require multiple classes. Summary class, customer class, order class and the driver class. Summary class This class will keep track of the cost of the order and output a summary, which includes the total for the order. The methods in this class are static. There are no instance variables, and instead uses an Order object that is passed...

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