Question: What is wrong with this code? using System; using System.Globalization; namespace GreenvilleRevenue { class Program { static void Main(string[] args) { int numContestants; do {

What is wrong with this code?

using System;

using System.Globalization;

namespace GreenvilleRevenue

{

class Program

{

static void Main(string[] args)

{

int numContestants;

do

{

Console.Write("Enter the number of contestants (0-30): ");

} while (!int.TryParse(Console.ReadLine(), out numContestants) || numContestants < 0 || numContestants > 30);

Contestant[] contestants = new Contestant[numContestants];

for (int i = 0; i < numContestants; i++)

{

string name, talentCode;

int age;

Console.WriteLine($"Contestant {i + 1}:");

Console.Write("Enter name: ");

name = Console.ReadLine();

Console.Write("Enter age: ");

while (!int.TryParse(Console.ReadLine(), out age) || age < 0)

{

Console.Write("Invalid age. Enter age: ");

}

Console.WriteLine("Talent codes are:");

Console.WriteLine("S Singing");

Console.WriteLine("D Dancing");

Console.WriteLine("M Musical instrument");

Console.WriteLine("O Other");

Console.Write("Enter talent code: ");

talentCode = Console.ReadLine();

Contestant contestant;

if (age <= 12)

{

contestant = new ChildContestant();

}

else if (age <= 17)

{

contestant = new TeenContestant();

}

else

{

contestant = new AdultContestant();

}

contestant.Name = name;

contestant.Age = age;

contestant.TalentCode = talentCode;

contestants[i] = contestant;

}

decimal totalRevenue = 0;

foreach (Contestant contestant in contestants)

{

totalRevenue += contestant.Fee;

}

Console.WriteLine("Revenue expected this year is {0}", totalRevenue.ToString("C", CultureInfo.GetCultureInfo("en-US")));

Console.WriteLine("Valid talent categories are:");

Console.WriteLine("S Singing");

Console.WriteLine("D Dancing");

Console.WriteLine("M Musical instrument");

Console.WriteLine("O Other");

while (true)

{

Console.Write("Enter a talent code to display all contestants with that talent (or 'exit' to quit): ");

string talentCode = Console.ReadLine();

if (talentCode.ToLower() == "exit")

{

break;

}

bool found = false;

foreach (Contestant contestant in contestants)

{

if (contestant.TalentCode.ToLower() == talentCode.ToLower())

{

Console.WriteLine(contestant.ToString());

found = true;

}

}

if (!found)

{

Console.WriteLine("Invalid talent code.");

}

}

}

}

class Contestant

{

public string Name { get; set; }

public int Age { get; set; }

public string TalentCode { get; set; }

public virtual decimal Fee { get; set; }

public override string ToString()

{

return string.Format("{0} Contestant {1} Fee {2}", GetType().Name, Name, Fee.ToString("C", CultureInfo.GetCultureInfo("en-US")));

}

}

class ChildContestant : Contestant

{

public override decimal Fee { get; set; } = 15.0m;

}

class TeenContestant : Contestant

{

public override decimal Fee { get; set; } = 20.0m;

}

class AdultContestant

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!