using System;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Conditional
{
class SwitchCase
{
public static void Main(string[] args)
{
int choice, distance;
double a, result;
char option;
string description;
Console.Write("Do you want to make a new entry or to view a previous entry[0, 1]: ");
choice = Convert.ToInt32(Console.ReadLine());
if (choice == 0) {
Console.Write("how many meters have you travelled: ");
distance = Convert.ToInt32(Console.ReadLine());
Console.Write("Select one:\na. Hatchback = 3\nb. SUV = 3.5\nc. Sports car = 4");
option = (char)Console.Read();
switch (option) {
case 'a': result = 3 * distance / 1000; break;
case 'b': result = 3.5 * distance / 1000; break;
case 'c': result = 4 * distance / 1000; break;
}
Console.Write("Enter a description: ");
description = Console.ReadLine();
List<data> _data = new List<data>();
_data.Add(new data()
{
Distance = distance,
description = description
});
string json = JsonSerializer.Serialize(_data);
File.WriteAllText(@".\path.json", json);
}
}
}
}
Comments
Leave a comment