Assignment is as follows:
"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."
Code runs fine outside of my "percent" variable always coming back as zero when listing the sales amount and percentage of total...my 4AM brain is stumped.
static void Main(string[] args)
{
int arraylength;
string inValue;
Console.WriteLine("Input desired length of array");
inValue = Console.ReadLine();
if (int.TryParse(inValue, out arraylength) == false)
Console.WriteLine("Invalid data entered - " +
"0 recorded for number of sales.");
int [] sales = new int [arraylength];
for (int i = 0; i < arraylength; i++)
{
inValue = Console.ReadLine();
sales[i] = int.Parse(inValue);
}
int sum = 0;
for (int i = 0; i < arraylength; i++)
{
sum += sales[i];
}
for (int i = 0; i < arraylength; i++)
{
int percent = sales[i] / sum;
Console.WriteLine("Sales amount is " + sales[i]);
Console.WriteLine("Percentage of total is " + percent);
}
Console.ReadKey();
}