Question: Now, using your code from Chapter 7 Case Study 1 , modify your program so every data entry statement uses a TryParse ( ) method
Now, using your code from Chapter Case Study modify your program so every data entry statement uses a TryParse method to ensure that each piece of data is the correct type.
I used the code below and still failed the test for Task #: All data entry statements use a TryParse method. I was wondering if someone could make sure TryParse method is in every place it should be
using System;
using static System.Console;
using System.Globalization;
class GreenvilleRevenue
static void Main
Variables
const int ENTRANCEFEE ;
const int MINCONTESTANTS ;
const int MAXCONTESTANTS ;
int numThisYear;
int numLastYear;
int revenue;
string names new stringMAXCONTESTANTS;
char talents new charMAXCONTESTANTS;
char talentCodes SDMO;
string talentCodesStrings "Singing", "Dancing", "Musical instrument", "Other" ;
int counts ; ;
Get Data and process data
numLastYear GetContestantNumberlast MINCONTESTANTS, MAXCONTESTANTS;
numThisYear GetContestantNumberthis MINCONTESTANTS, MAXCONTESTANTS;
revenue numThisYear ENTRANCEFEE;
WriteLineLast year's competition had contestants, and this year's has contestants",
numLastYear, numThisYear;
WriteLineRevenue expected this year is revenue.ToStringC CultureInfo.GetCultureInfoenUS;
DisplayRelationshipnumThisYear numLastYear;
GetContestantDatanumThisYear names, talents, talentCodes, talentCodesStrings, counts;
GetListsnumThisYear talentCodes, talentCodesStrings, names, talents, counts;
Contestant Number
public static int GetContestantNumberstring when, int min, int max
int num;
WriteEnter number of contestants year when;
whileint.TryParseReadLine out num
WriteInvalid Input. Enter number of contestants year when;
while num min num max
WriteLineNumber must be between and min, max;
WriteEnter number of contestants year when;
whileint.TryParseReadLine out num
WriteInvalid Input. Enter number of contestants year when;
return num;
public static void DisplayRelationshipint numThisYear, int numLastYear
if numThisYear numLastYear
WriteLineThe competition is more than twice as big this year!";
else
if numThisYear numLastYear
WriteLineThe competition is bigger than ever!";
else
if numThisYear numLastYear
WriteLineA tighter race this year! Come out and cast your vote!";
public static void GetContestantDataint numThisYear, string names, char talents, char talentCodes, string talentCodesStrings, int counts
int x ;
bool isValid;
while x numThisYear
WriteEnter contestant name ;
namesx ReadLine;
WriteLineTalent codes are:";
for int y ; y talentCodes.Length; y
WriteLine talentCodesy talentCodesStringsy;
Write Enter talent code ;
whilechar.TryParseReadLineout talentsx
WriteInvalid Input.Enter talent code ;
isValid false;
while isValid
for int z ; z talentCodes.Length; z
if talentsx talentCodesz
isValid true;
countsz;
if isValid
WriteLine is not a valid code", talentsx;
Write Enter talent code ;
whilechar.TryParseReadLineout talentsx
WriteInvalid Input.Enter talent code ;
x;
public static void GetListsint numThisYear, char talentCodes, string talentCodesStr
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
