using System;
namespace Library
{
public class Program
{
private static void Main(string[] args)
{
Console.WriteLine("Library program");
Console.WriteLine(new string('-', 50));
int books;
int days;
Console.WriteLine("Input number of books checked out: ");
while(!int.TryParse(Console.ReadLine(), out books))
Console.WriteLine("Wrong input. Please, try again.");
Console.WriteLine("Input number of days books are overdue: ");
while(!int.TryParse(Console.ReadLine(), out days))
Console.WriteLine("Wrong input. Please, try again.");
Calculate(books, days);
Console.WriteLine(new string('-', 50));
}
private static void Calculate(int books, int days)
{
int priceBeforeWeek = books * 20; // days <= 7
int priceAfterWeek = books * 50; // days >= 7
int priceInCents = 0;
for (int i = 1; i <= days; i++)
{
if (i <= 7)
priceInCents += priceBeforeWeek;
else
priceInCents += priceAfterWeek;
}
double result = (double)priceInCents / 100;
Console.WriteLine($"Total: {result:C}"); //formatting
}
}
}
Comments
Leave a comment