Programming Fundamentals Sample Exam II
Блокирах на най-простата задача "Soft Uni Airline". Тестовете ми излизат, обаче дава 20 точки. ако някой може да ми пососчи грешката?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace sample_exam
{
    class Program
    {
        static void Main(string[] args)
        {
            var flights = decimal.Parse(Console.ReadLine());
            decimal prophitMoney = 0;
            decimal lostMoney = 0;
            decimal overall = 0;
            for (int i = 1; i <= flights; i++)
            {
                var adults = decimal.Parse(Console.ReadLine());
                var adultTicketPrice = decimal.Parse(Console.ReadLine());
                var kids = decimal.Parse(Console.ReadLine());
                var kidsTicketPrice = decimal.Parse(Console.ReadLine());
                var fuelPrice = decimal.Parse(Console.ReadLine());
                var fuelConsumption = decimal.Parse(Console.ReadLine());
                var flightDuration = decimal.Parse(Console.ReadLine());
                decimal expences = flightDuration * fuelConsumption * fuelPrice;
                decimal income = (adults * adultTicketPrice) + (kids * kidsTicketPrice);
                
                decimal total = income - expences;
                
               
                if (total < 0)
                {
                    lostMoney += total;
                }
                else
                {
                    prophitMoney += total;
                }
     
            }
            overall = prophitMoney + lostMoney;
            if (lostMoney < 0)
                Console.WriteLine("We've got to sell more tickets! We've lost {0:f3}$." , lostMoney);
            if (prophitMoney > 0 && overall > 0 )
            {
                Console.WriteLine("You are ahead with {0:f3}$.", prophitMoney);
                Console.WriteLine("Overall profit -> {0:f3}$.", overall);
                Console.WriteLine("Average profit -> {0:f3}$.", overall / flights);
            }
        }
    }
}

Не е това. Номера е че сметките ми излизат точно и от двата примера, които има към задачата.
Значи може да е от типовете данни, които ползваш. Пробвай да ги направиш така, както е зададено в условието на задачата.
И където ти дава проблем с сметките му дай (decimal)([израз]).
Пробвах вече. Така го докарах до 60 (кода, който съм пейстнал долу), но пак не мога да разбера къде бъркам. Мерси все пак.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace sample_exam
{
class Program
{
static void Main(string[] args)
{
var flights = decimal.Parse(Console.ReadLine());
decimal totalMoney = 0;
for (int i = 0; i < flights; i++)
{
var adults = decimal.Parse(Console.ReadLine());
var adultTicketPrice = decimal.Parse(Console.ReadLine());
var kids = decimal.Parse(Console.ReadLine());
var kidsTicketPrice = decimal.Parse(Console.ReadLine());
var fuelPrice = decimal.Parse(Console.ReadLine());
var fuelConsumption = decimal.Parse(Console.ReadLine());
var flightDuration = decimal.Parse(Console.ReadLine());
var expences = flightDuration * fuelConsumption * fuelPrice;
var income = (adults * adultTicketPrice) + (kids * kidsTicketPrice);
var total = income - expences;
//var averageProphit = total / flights;
totalMoney += total;
if (total < 0)
{
Console.WriteLine("We've got to sell more tickets! We've lost {0:f3}$.", total);
}
else
{
Console.WriteLine("You are ahead with {0:f3}$.", total);
}
}
if (totalMoney >= 0)
{
Console.WriteLine("Overall profit -> {0:f3}$.", totalMoney);
Console.WriteLine("Average profit -> {0:f3}$.", totalMoney / flights);
}
}
}
}