Question
IN C# In previous chapters, you created applications for the Greenville Idol competition. Now, modify the version of the GreenvilleRevenue program created in Chapter 5
IN C#
In previous chapters, you created applications for the Greenville Idol competition.
Now, modify the version of the GreenvilleRevenueprogram created in Chapter 5 so that after the user enters the number of contestants in this years competition, the user is prompted for the appropriate number of contestant names and a code for each contestant that indicates the type of talent:
S for singing
D for dancing
M for playing a musical instrument
O for other.
Make sure that all entered codes are valid, and if not, reprompt the user to enter a correct code. For example, if Y is input, output Y is not a valid code, and reprompt the user until a valid code is entered.
After contestant data entry is complete, display a count of each type of talent. For example, if there were ten singers, four dancers, 7 people who play musical instruments, and 1 in the other category, the output should be:
The types of talent are: Singing 10 Dancing 4 Musical instrument 7 Other 1
Then, continuously prompt the user for a talent code until the user enters a sentinel value (the uppercase character Zshould be used as the sentinel value).
With each code entry, display a list of the contestants with that code, or display a message that the code is not valid and reprompt the user. For example, if M is entered, the output might be:
Contestants with talent Musical instrument are: Michelle Nick
If U is entered, the output should be U is not a valid code.
Code to reuse is below:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace GreenvilleRevenue1 { class Program { static void Main(string[] args) { int contCurr; int contLast; Console.WriteLine("Please enter the number of contestants from last years contest"); contLast = cont(); Console.WriteLine(" Please enter the number of contestants from this years contest"); contCurr = cont(); array(contCurr); comp(contCurr, contLast);
}
public static int cont() { int last = 0; string b; b= (Console.ReadLine()); int.TryParse(b, out last); while (last > 30 || last < 0) { Console.WriteLine(" You have entered and invalid response, please enter a valid number between 0 and 30."); b = (Console.ReadLine()); int.TryParse(b, out last); } return last; }
public static void array(int thisyear) { string[] contestant = new string[thisyear]; string[] skill = new string[thisyear]; for (int x = 0; x < thisyear; ++x) { Console.WriteLine(" Please enter contestant " + (x + 1) + "'s name"); contestant[x] = Console.ReadLine(); bool correct = false; while (!correct) { Console.WriteLine(" Please enter contestant " + (x + 1) + " 's skill, 'S' for sing 'D' for dance 'M' for " + "musical instrument 'O' for other"); string type = Console.ReadLine().ToUpper();
if (type == "S" || type == "D" || type == "M" || type == "O") { skill[x] = type; correct = true; } else { Console.WriteLine(" Please enter a valid parameter"); } } } talent(skill, contestant); }
public static void talent(string[] skill, string[] contestant) { int dance = 0; int instrument = 0; int sing = 0; int other = 0; string entry; for (int x = 0; x < skill.Length; ++x) {
if (skill[x] == "O") { ++other; } else if (skill[x] == "S") { ++sing; } else if (skill[x] == "D") { ++dance; } else if (skill[x] == "M") { ++instrument; }
} Console.Clear(); Console.WriteLine("There are:"); Console.WriteLine("{0} dancers", dance); Console.WriteLine("{0} singers", sing); Console.WriteLine("{0} musicians", instrument); Console.WriteLine("{0} contestant(s) with other skills", other); Console.WriteLine(" Please enter a skill code 'S' 'D' 'M' 'O' to see a list of contestants with that skill or enter '!' to exit"); entry = Console.ReadLine().ToUpper(); while (entry != "!") { if (entry != "S" && entry != "D" && entry != "M" && entry != "O") { Console.WriteLine(" Please try again: Enter a VALID skill code 'S' 'D' 'M' 'O' to see a list of contestants with that skill or '!' to exit"); entry = Console.ReadLine().ToUpper(); if (entry == "!") break; } for (int x = 0; x < skill.Length; ++x) { if (entry == skill[x]) Console.WriteLine(" Contestant " + contestant[x] + " skill " + skill[x]); } Console.WriteLine(" Please enter a skill code 'S' 'D' 'M' 'O' to see a list of contestants with that skill or enter '!' to exit"); entry = Console.ReadLine().ToUpper(); } }
public static void comp(int contCurr, int contLast) {
if (contCurr > contLast * 2) { Console.WriteLine(" The competition is more than twice as big this year! "); Console.WriteLine(" The revenue expected for this year's competition is {0:C}", (contCurr * 25)); } else
if (contCurr > contLast && contCurr <= (contLast * 2)) { Console.WriteLine(" The competition is bigger than ever! "); Console.WriteLine(" The revenue expected for this year's competition is {0:C}", (contCurr * 25)); } else
if (contCurr < contLast) { Console.WriteLine(" A tighter race this year! Come out and cast your vote! "); Console.WriteLine(" The revenue expected for this year's competition is {0:C}", (contCurr * 25)); } } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started