Skip to content

Instantly share code, notes, and snippets.

@profesor79
Created September 23, 2017 22:09
Show Gist options
  • Save profesor79/b357ff05a7c05450c0d1c69d6e279677 to your computer and use it in GitHub Desktop.
Save profesor79/b357ff05a7c05450c0d1c69d6e279677 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FranclinMath
{
class Program
{
static void Main(string[] args)
{
}
}
public class SalesReport
{
private string[] months = new[] { "Jan", "feb" };
private string[] makus = new[] { "opel", "fiat" };
int[,] salesData =
{
{ 0, 102 }, { 0, 56 }, { 0, 55 }, { 0, 67 }, { 0, 19 }, { 0, 8 },
{ 1, 17 }, { 1, 8 }, { 1, 4 }, { 1, 0 }, { 1, 0 }, { 1, 0 }
};
private int numberOfCars = 2;
private int numberOfMonths = 6;
private int[] salesSumByMake;
private int[] salesSumByMonth;
private int totalSum = 0;
public int CalculateBestSellingCar()
{
CalculateSales();
var bestSellingCarMake = 0;
var soldCars = 0;
for (int currentCar = 0; currentCar < numberOfCars; currentCar++)
{
if (salesSumByMake[currentCar] > soldCars)
{
bestSellingCarMake = currentCar;
soldCars = salesSumByMake[currentCar];
}
}
return bestSellingCarMake;
}
public int CalculateBestSellingMonth()
{
CalculateSales();
var bestSellingMonth = 0;
var soldCars = 0;
for (int currentMonth = 0; currentMonth < numberOfMonths; currentMonth++)
{
if (salesSumByMonth[currentMonth] > soldCars)
{
bestSellingMonth = currentMonth;
soldCars = salesSumByMake[currentMonth];
}
}
Console.WriteLine($"best month is:{months[bestSellingMonth]}");
return bestSellingMonth;
}
private void CalculateSales()
{
salesSumByMake = new int[numberOfCars];
salesSumByMonth = new int[numberOfMonths];
for (int currentCar = 0; currentCar < numberOfCars; currentCar++)
{
for (int month = 0; month < numberOfMonths; month++)
{
salesSumByMake[currentCar] += salesData[currentCar, month];
salesSumByMonth[month] += salesData[currentCar, month];
totalSum += salesData[currentCar, month];
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment