-
Notifications
You must be signed in to change notification settings - Fork 0
/
GreenvilleRevenue.cs
135 lines (134 loc) · 4.71 KB
/
GreenvilleRevenue.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using static System.Console;
class GreenvilleRevenue
{
static void Main()
{
const int ENTRANCE_FEE = 25;
const int MIN_CONTESTANTS = 0;
const int MAX_CONTESTANTS = 30;
int numThisYear;
int numLastYear;
int revenue;
string[] names = new string[MAX_CONTESTANTS];
char[] talents = new char[MAX_CONTESTANTS];
char[] talentCodes = {'S', 'D', 'M', 'O'};
string[] talentCodesStrings = {"Singing", "Dancing", "Musical instrument", "Other"};
int[] counts = {0, 0, 0, 0};;
numLastYear = GetContestantNumber("last", MIN_CONTESTANTS, MAX_CONTESTANTS);
numThisYear = GetContestantNumber("this", MIN_CONTESTANTS, MAX_CONTESTANTS);
revenue = numThisYear * ENTRANCE_FEE;
WriteLine("Last year's competition had {0} contestants, and this year's has {1} contestants",
numLastYear, numThisYear);
WriteLine("Revenue expected this year is {0}", revenue.ToString("C"));
DisplayRelationship(numThisYear, numLastYear);
GetContestantData(numThisYear, names, talents, talentCodes, talentCodesStrings, counts);
GetLists(numThisYear, talentCodes, talentCodesStrings, names, talents, counts);
}
public static int GetContestantNumber(string when, int min, int max)
{
string entryString;
int num;
Write("Enter number of contestants {0} year >> ", when);
entryString = ReadLine();
num = Convert.ToInt32(entryString);
while(num < min || num > max)
{
WriteLine("Number must be between {0} and {1}", min, max);
Write("Enter number of contestants {0} year >> ", when);
entryString = ReadLine();
num = Convert.ToInt32(entryString);
}
return num;
}
public static void DisplayRelationship(int numThisYear, int numLastYear)
{
if(numThisYear > 2 * numLastYear)
WriteLine("The competition is more than twice as big this year!");
else
if(numThisYear > numLastYear)
WriteLine("The competition is bigger than ever!");
else
if(numThisYear < numLastYear)
WriteLine("A tighter race this year! Come out and cast your vote!");
}
public static void GetContestantData(int numThisYear, string[] names, char[] talents, char[] talentCodes, string[] talentCodesStrings, int[] counts)
{
int x = 0;
bool isValid;
while(x < numThisYear)
{
Write("Enter contestant name >> ");
names[x] = ReadLine();
WriteLine("Talent codes are:");
for(int y = 0; y < talentCodes.Length; ++y)
WriteLine(" {0} {1}", talentCodes[y], talentCodesStrings[y]);
Write(" Enter talent code >> ");
talents[x] = Convert.ToChar(ReadLine());
isValid = false;
while(!isValid)
{
for(int z = 0; z < talentCodes.Length; ++z)
{
if(talents[x] == talentCodes[z])
{
isValid = true;
++counts[z];
}
}
if(!isValid)
{
WriteLine("{0} is not a valid code", talents[x]);
Write(" Enter talent code >> ");
talents[x] = Convert.ToChar(ReadLine());
}
}
++x;
}
}
public static void GetLists(int numThisYear, char[] talentCodes, string[] talentCodesStrings, string[] names, char[] talents, int[] counts)
{
int x;
char QUIT = 'Z';
char option;
bool isValid;
int pos = 0;
bool found;
WriteLine("\nThe types of talent are:");
for(x = 0; x < counts.Length; ++x)
WriteLine("{0, -20} {1, 5}", talentCodesStrings[x], counts[x]);
Write("\nEnter a talent type or {0} to quit >> ", QUIT);
option = Convert.ToChar(ReadLine());
while(option != QUIT)
{
isValid = false;
for(int z = 0; z < talentCodes.Length; ++z)
{
if(option == talentCodes[z])
{
isValid = true;
pos = z;
}
}
if(!isValid)
WriteLine("{0} is not a valid code", option);
else
{
WriteLine("\nContestants with talent {0} are:", talentCodesStrings[pos]);
found = false;
for(x = 0; x < numThisYear; ++x)
{
if(talents[x] == option)
{
WriteLine(names[x]);
found = true;
}
}
if(!found)
WriteLine("No contestants had talent {0}", talentCodesStrings[pos]);
}
Write("\nEnter a talent type or {0} to quit >> ", QUIT);
option = Convert.ToChar(ReadLine());
}
}
}