-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFriendsList.cs
86 lines (75 loc) · 2.69 KB
/
FriendsList.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
using System;
class Program
{
public static void Main(string[] args)
{
int choice, index;
string input;
string[] name = new string[5];
for (int i = 0; i < name.Length; i++)
{
name[i] = "";
}
Console.WriteLine("[Top 5 Friend’s List]");
do
{
Console.Write("What would you like to do?\n1) Enter a friend’s name\n2) Replace a friend’s name\n3) Display your friends list\n4) Quit\nYour choice: ");
choice = Convert.ToInt32(Console.ReadLine());
switch (choice)
{
case 1:
bool placed = false;
Console.Write("Enter a name: ");
input = Console.ReadLine();
for (int i = 0; i < name.Length; i++)
{
if (name[i] == "")
{
name[i] = input;
placed = true;
break;
}
else
{
if (name[i] == input)
{
placed = true;
Console.Write("Sorry, they’re already on the list!\n");
break;
}
}
}
if (placed == false)
{
Console.Write("Sorry, your friends list is full!\n");
}
break;
case 2:
Console.Write("Enter a name: ");
string newFriend = Console.ReadLine();
Console.Write("Enter an index: ");
index = Convert.ToInt32(Console.ReadLine());
if (1< index && index >5)
{
Console.Write("Sorry, that’s an invalid command!\n");
}
else
{
int actIndex = (index - 1);
string oldFriend = name[actIndex];
name[actIndex] = newFriend;
}
break;
case 3:
Console.Write("Friend’s List: ");
Console.Write("\n");
for (int i = 0; i < name.Length; i++)
{
Console.Write((i + 1) + ") " + name[i]);
Console.Write("\n");
}
break;
}
} while (choice != 4);
}
}