/SoftUni Airline.cs Secret
Created
June 11, 2016 16:27
SoftUni Airline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class SoftUni_Airline | |
{ | |
public static void Main() | |
{ | |
int flightsCount = int.Parse(Console.ReadLine()); | |
decimal overallProfit = CalcProfit(flightsCount); | |
Console.WriteLine("Overall profit -> {0:f3}$.", overallProfit); | |
Console.WriteLine("Average profit -> {0:f3}$.", overallProfit / flightsCount); | |
} | |
static decimal CalcProfit(int flightsCount) | |
{ | |
decimal overallProfit = 0; | |
for (int n = 0; n < flightsCount; n++) | |
{ | |
decimal income = 0; | |
for (int i = 0; i < 2; i++) | |
{ | |
decimal passengersCount = int.Parse(Console.ReadLine()); | |
decimal ticketPrice = decimal.Parse(Console.ReadLine()); | |
income += passengersCount * ticketPrice; | |
} | |
decimal expenses = 1; | |
for (int i = 0; i < 2; i++) | |
expenses *= decimal.Parse(Console.ReadLine()); // fuel consumption * fuel price | |
expenses *= int.Parse(Console.ReadLine()); // flight duration | |
decimal profitPerFlight = income - expenses; | |
overallProfit += profitPerFlight; | |
if (profitPerFlight >= 0) Console.WriteLine("You are ahead with {0:f3}$.", profitPerFlight); | |
else Console.WriteLine("We've got to sell more tickets! We've lost {0:f3}$.", profitPerFlight); | |
} | |
return overallProfit; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment