2. The Ion Realty Sales Corporation would like to have a listing of their sales over the past few months. Write a program that accepts any number of monthly sales amounts. Display the total of the values. Display a report showing each original value entered and the percentage that value contributes to the total. You may prompt the user for the number of values to be inputted.
internal class Program
{
class IonRealtySalesCorporation
{
public decimal[] MonthlySalesAmounts { get; set; }
public IonRealtySalesCorporation(int NumberOfMonths)
{
MonthlySalesAmounts = new decimal[NumberOfMonths];
}
public override string ToString()
{
string report = "";
for (int i = 0; i < MonthlySalesAmounts.Length; i++)
{
report += $"Month number: {i + 1},sales this month: {MonthlySalesAmounts[i]}, " +
$"percentage of the total: {(int)(MonthlySalesAmounts[i]*100/ MonthlySalesAmounts.Sum())}%\n";
}
report += $"Total sales: {MonthlySalesAmounts.Sum()}";
return report;
}
}
static void Main(string[] args)
{
Console.Write("Enter the number of last months you want to receive a report for: ");
IonRealtySalesCorporation ionRealtySalesCorporation = new IonRealtySalesCorporation(int.Parse(Console.ReadLine()));
IncomeRecord(ionRealtySalesCorporation);
Console.WriteLine(ionRealtySalesCorporation);
Console.ReadKey();
}
static void IncomeRecord(IonRealtySalesCorporation ionRealtySalesCorporation)
{
for (int i = 0; i < ionRealtySalesCorporation.MonthlySalesAmounts.Length; i++)
{
Console.Write($"Enter the amount of income for {i + 1} month: ");
ionRealtySalesCorporation.MonthlySalesAmounts[i] = decimal.Parse(Console.ReadLine());
}
}
}
Comments
Leave a comment