Question: C# coding: Instructions: In previous chapters, you created applications for the Greenville Idol competition. Now, modify your version of the GreenvilleRevenue program created in Chapter
C# coding:
Instructions:
In previous chapters, you created applications for the Greenville Idol competition.
Now, modify your version of the GreenvilleRevenue program 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, re-prompt the user to enter a correct code. For example, if Y is input, output Y is not a valid code, and re-prompt 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, seven people who play musical instruments, and one 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 Z should 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 re-prompt 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.
In order to prepend the $ to currency values, the program will need to use the CultureInfo.GetCultureInfo method. In order to do this, include the statement using System.Globalization; at the top of your program and format the output statements as follows: WriteLine("This is an example: {0}", value.ToString("C", CultureInfo.GetCultureInfo("en-US")));
My code: I get a lot of errors. I was wondering if you could fix the errors and make it runs:
using System;
using static System.Console;
using System.Globalization;
class GreenvilleRevenue
{
static void Main()
{
// Your code here
public static string[] arr;
public static string[] arr;
public Program(int year)
{
arr = new string [year];
name = new string[year];
countyr = year;
}
public static int acceptCont
(int a)
{
int number = 0;
if(a > 0 & a < 30)
number = a;
return number;
}
public void compare
(int a, int b)
{
if(b==(2*a))
WriteLine("The competition is twice as big this year");
if(b>a && b<(2*a))
WriteLine("The competition is bigger than ever!");
else
WriteLine("Tighter race this year! Come out and cast your vote");
}
public void anter()
{
int counts = 0, countd = 0,
coutm = 0, counto = 0;
WriteLine("Enter contestant name and talent code ");
for(int i==0; i { name[i] = Console.ReadLine(); arr[i] = Console.ReadLine(); } for(int i = 0; i { if(arr[i]=="S") counts++; else if(arr[i]=="D") countd++; else if(arr[i]=="M") countm++; else if(arr[i]=="O") counto++; } WriteLine("Total count of" + "Contestant in each category: 1.Singing {0} 2.Dancing {1} 3.Musical Instrument {2} 4.Others {3}", counts, countd, countm, counto); } public void display() { WriteLine("The expected revenue is:$" + (25*countyr)); } public void getNames() { string choice; WriteLine("Enter a valid talent code to view the list!"); choice=Console.ReadLine(); while(choice !="0") { WriteLine("Remember that sentinel is 0. Enter again!"); choice=Console.ReadLine(); switch (choice) { case "S": for(int i=0; i i++) { if(arr[i]=="S") { WriteLine(name[i]); } } break; case"D": for(int i=0; i i++) { if(arr[i]=="D") { WriteLine(name[i]); } } break; case"M": for(int i=0; i i++) { if (arr[i]=="M") { WriteLine(name[i]); } } break; case"O": for(int i=0; i i++) { if(arr[i]=="O") { WriteLine(name[i]); } } break; } } } static void Main(string[]args) { int yr1, yr2; WriteLine("Enter last year's no. of contestants"); yr1= acceptCont(Convert.ToInt32 (Console.ReadLine())); WriteLine("Enter this year's no. of contestants"); yr2= acceptCont(Convert.ToInt32(Console.ReadLine())); Program obj = new Program(yr2); obj.compare(yr1, yr2); obj.enter(); WriteLine(" The valid talent codes are S,D,M,O"); obj.getNames(); Console.ReadLine(); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
