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();
}
}
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:
output:
If you have any queries, please comment below.
Please upvote , if you like this answer.
C SHARP PROGRAM LANGUAGE The program below isn't working quite right. First compile and run it...
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 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...