Problem
In C#. Share Step by step photos how to do it. If the code needs to be change you can do so. convert the code into a Windows Forms application. You may choose to change your array into a list or other type of collection.
Design the form so that users may enter their name and base amount, and select options and add ons for the order. When an order is placed (by clicking on a button), the customer's name is placed in a listbox on the Windows Form. When the user selects a name on the list, their total order amount appears in a label on the form in addition to being added to an array/list/collection. When the user exits the program, the order information is read from the array/list/collection to a file.
using System;
using System.IO;
class Program
{
static void Main()
{
const int MAX_ORDERS = 100;
string storeName = "PS5 Place";
string mainItem = "PS5 Console";
double[] orderAmounts = new double[MAX_ORDERS];
string[] customerNames = new string[MAX_ORDERS];
int orderCount = 0;
double basePrice, optionPrice = 0, addOnPrice = 0;
string customerName, optionChoice, addOnChoice;
bool extraController, spiderManGame, headset;
Console.WriteLine("Welcome to " + storeName + "!");
while (true)
{
Console.WriteLine("Select a menu item:");
Console.WriteLine("1. Place an Order");
Console.WriteLine("2. Finish for the day");
string choice = Console.ReadLine();
if (choice == "1")
{
Console.Write("Enter Customer Name: ");
customerName = Console.ReadLine();
Console.Write("Enter " + mainItem + " Base Price: ");
basePrice = double.Parse(Console.ReadLine());
Console.WriteLine("Press 1 for the digital edition or 2 for regular console:");
optionChoice = Console.ReadLine();
if (optionChoice == "2")
{
optionPrice = 100;
}
Console.Write("Add an extra controller? (y/n): ");
extraController = (Console.ReadLine().ToLower() == "y");
if (extraController)
{
addOnPrice += 69.99;
}
Console.Write("Add a Spider Man game? (y/n): ");
spiderManGame = (Console.ReadLine().ToLower() == "y");
if (spiderManGame)
{
addOnPrice += 49.99;
}
Console.Write("Add a Headset? (y/n): ");
headset = (Console.ReadLine().ToLower() == "y");
if (headset)
{
addOnPrice += 99.99;
}
double orderAmount = basePrice + optionPrice + addOnPrice;
orderAmounts[orderCount] = orderAmount;
customerNames[orderCount] = customerName;
orderCount++;
Console.WriteLine(tiny_mce_markerquot;Order placed for {customerName} ${orderAmount:F}");
}
else if (choice == "2")
{
if (orderCount > 0)
{
Console.WriteLine("Daily orders have been printed to the file orders.txt.");
using (StreamWriter file = new StreamWriter("orders.txt"))
{
for (int i = 0; i < orderCount; i++)
{
file.WriteLine(tiny_mce_markerquot;{customerNames[i]}, ${orderAmounts[i]:F}");
}
}
}
else
{
Console.WriteLine("No orders were placed today.");
}
Console.WriteLine("Have a great rest of your day!");
break;
}
}
}
}