Skip to content

Instantly share code, notes, and snippets.

@astambi
Created June 11, 2016 16:27

Revisions

  1. astambi created this gist Jun 11, 2016.
    36 changes: 36 additions & 0 deletions SoftUni Airline.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    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;
    }
    }