Hi there all,
My task is to create a sales calculator, where sales up to 500 are given a 3.5% commission rate, up to 1000 are given 4% and above 1000 are given 5%.
The total sales are tallied, and increment a number of sales counter.
This is then divided to give an average sale.
commission due is based upon the commission rate times the sales amount.
if average sales at least 50 and commission rate is 4%, then a bonus level is set to true and an additional $25 is added to the commission rate.
if average is at least 75 and commission rate is 5% then a bonus level is set to true and an additional $200 is added.
Am i going in the right way with this? also, what is 'use of unassigned variable? this is my code thus far:
My task is to create a sales calculator, where sales up to 500 are given a 3.5% commission rate, up to 1000 are given 4% and above 1000 are given 5%.
The total sales are tallied, and increment a number of sales counter.
This is then divided to give an average sale.
commission due is based upon the commission rate times the sales amount.
if average sales at least 50 and commission rate is 4%, then a bonus level is set to true and an additional $25 is added to the commission rate.
if average is at least 75 and commission rate is 5% then a bonus level is set to true and an additional $200 is added.
Am i going in the right way with this? also, what is 'use of unassigned variable? this is my code thus far:
Code:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace sampleapp1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
string saleAmount;
int numSales;
double addingSales;
double ttlSales;
double avgSale;
double commDue;
double commRate;
bool bnsLevel;
double bnsAmount;
double ttlCommDue;
saleAmount = Console.ReadLine();
//Validation to perform
if (validateInput(saleAmount))
{
// convert string
addingSales = Convert.ToInt32(Convert.ToDouble(saleAmount));
ttlSales += addingSales;
numSales++;
avgSale = ttlSales / numSales;
commDue += (commRate * addingSales);
if (ttlSales <= 500.00)
{
commRate = 3.5;
}
else if (ttlSales < 999.99)
{
commRate = 4;
}
else
{
commRate = 5;
}
if (ttlSales <= 500.00)
{
if (avgSale >= 50.00 && avgSale < 75.00 && commRate == 4)
{
bnsLevel = true;
bnsAmount = 25.00;
ttlCommDue = (commDue + bnsAmount);
}
else if (avgSale >= 75.00 && commRate == 5)
{
bnsLevel = true;
bnsAmount = 200.00;
ttlCommDue = (commDue + bnsAmount);
}
else if (avgSale >= 1000 && commRate == 5)
{
bnsLevel = true;
bnsAmount = 200.00;
ttlCommDue = (commDue + bnsAmount);
}
else
{
bnsLevel = false;
ttlCommDue = commDue;
}
}
else if (ttlSales <= 1000.00)
{
if (avgSale >= 50.00 && avgSale < 75.00 && commRate == 4)
{
bnsLevel = true;
bnsAmount = 25.00;
ttlCommDue = (commDue + bnsAmount);
}
else if (avgSale >= 75.00 && commRate == 5)
{
bnsLevel = true;
bnsAmount = 200.00;
ttlCommDue = (commDue + bnsAmount);
}
else if (avgSale >= 1000 && commRate == 5)
{
bnsLevel = true;
bnsAmount = 200.00;
ttlCommDue = (commDue + bnsAmount);
}
else
{
bnsLevel = false;
ttlCommDue = commDue;
}
}
}
}
// Function to Test for Positive Number both Integer & Real
private static bool validateInput(string s)
{
Regex r = new Regex(@"^\d+(\.\d{1,2})?$");
return r.IsMatch(s);
}
}
}