First of all I would create a separate class for storing your phones data:
public class Phone
{
public string Manufacturer { get; set; }
public string Model { get; set; }
public bool HasCord { get; set; }
public double Price { get; set: }
}
Then instead of:
static void inputPhone(ref string manufacturer, ref string model, ref bool hasCord, ref double price)
You could have:
static Phone GetPhone()
And you could create an instance of a Phone inside GetPhone method and return the object that is filled in with appropriate data.
Instead of:
double[] prices = new double[100];
string[] manufacturers = new string[100];
string[] models = new string[100];
bool[] hasCords = new bool[100];
You could then have:
List<Phone> phones = new List<Phone>();
And then after each call to GetInput (previously: inputPhone) add it to the list:
phones.Add(GetPhone());
Then change the outputPhones to:
static void DisplayPhones(List<Phone> phones)
So all in all your code would look like this:
static Phone GetPhone()
{
Phone phone = new Phone();
Console.Write("Enter the phone manufacturer: ");
phone.Manufacturer = Console.ReadLine();
Console.Write("Enter the phone model: ");
phone.Model = Console.ReadLine();
Console.Write("Is it cordless? [Y or N]: ");
phone.HasCord = Console.ReadLine().ToUpper() == "Y";
Console.Write("Enter the phone price: ");
phone.Price = Convert.ToDouble(Console.ReadLine());
return phone;
}
static void DisplayPhones(List<Phone> phones)
{
for (int i = 0; i < phones.Count; i++)
{
Console.WriteLine("==Phone #{0}==", i);
Console.WriteLine("Phone Manufacturer: {0}", phones[i].Manufacturer);
Console.WriteLine("Phone Model: {0}", phones[i].Model);
Console.WriteLine("Has Cord: {0}", phones[i].HasCord ? "Yes" : "No");
Console.WriteLine("Phone Price: {0}", phones[i].Price);
}
Console.WriteLine("Number of phones entered: {0}", phones.Count);
}
static void Main(string[] args)
{
List<Phone> phones = new List<Phone>();
bool shouldContinue = true;
do
{
phones.Add(GetPhone());
Console.Write("Would like to process another phone? [Y or N]: ", shouldContinue);
shouldContinue = Console.ReadLine().ToUpper() == "Y";
} while (shouldContinue == true);
if (shouldContinue == false)
{
DisplayPhones(phones);
}
}
continueis a keyword in C#, I would suggest naming that variable something different (e.g.shouldContinue).List<Phone>instead