i have to make a simple ticket system where a person inputs name, number of adults and children and gets back the amount of money they have to pay (children get a 75% discount) and i cant seem to figure out how to do the calculation in code, and since there is only one teacher for about 500 students getting an answer from them isnt much of an option. Thanks in advance for any kind of help!
CodePudding user response:
Are you looking for sth like this?
double cost = 10;
Console.WriteLine("Number of Adults");
var adults = Console.ReadLine();
var numberOfAdults = 0;
if (adults != null) numberOfAdults = int.Parse(adults);
Console.WriteLine("Number of Children");
var children = Console.ReadLine();
var numberOfChildren = 0;
if (children != null) numberOfChildren = int.Parse(children);
double price = numberOfAdults * cost numberOfChildren * cost * 0.25;
Console.WriteLine($"Price: ${price}.");
Console.ReadLine();