Hi guys,
I just cant work out why my program is behaving differently to the tutorial im following, i have checked the code again and again (Though i bet you its something stupid i missed, usually is)
the problem im having, where his program is different is that after he creates a new car object, he is presented with the menu again:
Choose an action: \n(0) to quit \n(1) to add to inventory \n(2) to add a car to cart \n(3) to checkout"
where my program just wants to add a car again without presenting the earlier objects, its like the method just isnt being called again to take a user choice, and i dont know why.
this line seems to be the first i see after i create a new car.
also, what is the difference between
static public
and
public static?
I just cant work out why my program is behaving differently to the tutorial im following, i have checked the code again and again (Though i bet you its something stupid i missed, usually is)
the problem im having, where his program is different is that after he creates a new car object, he is presented with the menu again:
Choose an action: \n(0) to quit \n(1) to add to inventory \n(2) to add a car to cart \n(3) to checkout"
where my program just wants to add a car again without presenting the earlier objects, its like the method just isnt being called again to take a user choice, and i dont know why.
this line seems to be the first i see after i create a new car.
also, what is the difference between
static public
and
public static?
C#:
C#:
using CarClassLibrary;
using System;
namespace CarShopConsoleApp
{
class Program
{
static void Main(string[] args)
{
Store s = new Store();
Console.WriteLine("Welcome to the car store. First you must create some car inventory. Then you may add some cars to the shopping cart. Finally you can checkout which will give you the value of the shopping cart.");
int action = ChooseAction();
while (action != 0)
{
Console.WriteLine("You chose " + action);
switch (action)
{
case 1:
Console.WriteLine("You chose to add a new car to the inventory.");
string carMake = "";
string carModel = "";
Decimal carPrice = 0;
Console.WriteLine("What is the car make? eg: Ford, Nissan, Toyota etc");
carMake = Console.ReadLine();
Console.WriteLine("What is the car model? eg: Cortina, Sentra, Corrola etc");
carModel = Console.ReadLine();
Console.WriteLine("What is the car price?");
carPrice = int.Parse(Console.ReadLine());
Car newCar = new Car(carMake, carModel, carPrice);
s.CarList.Add(newCar);
PrintInventory(s);
break;
}
}
}
private static void PrintInventory(Store s)
{
foreach(Car c in s.CarList)
{
Console.WriteLine("Car: " + c.Make + " " + c.Model + " " + c.Price);
}
}
static public int ChooseAction ()
{
int choice = 0;
Console.WriteLine("Choose an action: \n(0) to quit \n(1) to add to inventory \n(2) to add a car to cart \n(3) to checkout");
choice = int.Parse(Console.ReadLine());
return choice;
}
}
}