hello, below i done a coding on visual studios but theres an error that keeps showing which is underlined and bold below, can you fix this?
hello, below i done a coding on visual studios but theres an error that keeps showing which is underlined and bold below, can you fix this?
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
hello, below i done a coding on visual studios but theres an error that keeps showing which is underlined and bold below, can you fix this?
class Program
{
static void Main(string[] args)
{
List<String> nameList = new List<String>();
int choice;
do
{
DisplayMenu();
choice = Convert.ToInt32(Console.ReadLine());
switch (choice)
{
case 1:
{ // if user enters option 1
Console.WriteLine("\nShow Names:\n-----------");
DisplayAllNames(nameList);
break;
}
case 2:
{ // if user enters option 2
Console.WriteLine("\nAdd Name:\n---------");
AddName(nameList);
break;
}
case 3:
{ // if user enters option 3
Console.WriteLine("\nChange Name:\n------------");
ChangeName(nameList);
break;
}
case 4:
{ // if user enters option 4
Console.WriteLine("\nRemove Name:\n------------");
RemoveName(nameList);
break;
}
case 5:
{ // if user enters option 5
Console.WriteLine("\nGoodbye!\n");
break;
}
default: // if user enters any other option
Console.WriteLine("\nInvalid choice!\n");
break;
}
} while (choice != 5);
}
public static void DisplayMenu()
{
Console.Write("Choose from the following options:\n(1) Show Names\n(2) Add Name\n(3) Change Name\n(4) Remove Name\n(5) Exit\nYour selection: ");
}
public static void DisplayAllNames(List<String> names)
{
if (names.Count == 0)
{
Console.WriteLine("List is empty!\n");
return;
}
Console.WriteLine("There are {0} names in the list:", names.Count);
for (int i = 0; i < names.Count; i++)
{
Console.WriteLine(names[i]);
}
Console.WriteLine();
}
public static int indexOf(List<String> names, String name)
{
int index = -1;
for (int i = 0; i < names.Count; i++)
{
if (names[i].ToLower() == name.ToLower())
{
index = i;
break;
}
}
return index; // return the index
}
public static void AddName(List<String> names)
{
Console.Write("Enter the name to add: ");
String userName = Console.ReadLine().Trim();
if (indexOf(names, userName) != -1)
{
Console.WriteLine("{0} is already in the list!\n", userName);
return;
}
names.Add(userName);
Console.WriteLine("{0} is added to the list.\n", userName); // display a confirmation message
}
public static void ChangeName (List<String> names)
{
Console.Write("Enter an old name: ");
String userName = Console.ReadLine().Trim();
int indexOfName = indexOf(names, userName);
if (indexOfName == -1)
{
Console.WriteLine("{0} is not present in the list!\n", userName);
return;
}
Console.Write("Enter a new name to update: ");
String newUserName = Console.ReadLine().Trim();
names[indexOfName] = newUserName;
Console.WriteLine("The name is successfully updated to: {0}.\n", newUserName);
}
public static void RemoveName (List<String>names)
{
Console.Write("Enter a name to remove: ");
String userName = Console.ReadLine().Trim();
int indexOfName = indexOf(names, userName);
if (indexOfName == -1)
{
Console.WriteLine("{0} is not present in the list!\n", userName); // display a message that the name is not present in the list
return;
}
names.RemoveAt(indexOfName);
Console.WriteLine("{0} is successfully removed from the list.\n", userName);
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 9 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education