Skip to content

Instantly share code, notes, and snippets.

@astambi
Created June 11, 2016 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astambi/8cf4f74cfe4ce8a1226d03835bd11692 to your computer and use it in GitHub Desktop.
Save astambi/8cf4f74cfe4ce8a1226d03835bd11692 to your computer and use it in GitHub Desktop.
SoftUni Airline
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