the program is to loop through until someone pushes the exit, else there is a box to allow input, set as string, which is converted later on. while entering the only other button, (add) is to be greyed out until value entered. this is what i have thus far, am i going in the right direction? or should this be in the form1.designer.cs?
Code:
// Using Directives
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace SalesCalc
{
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 txtSaleAmt;
int txtNumSales = 0;
double addingSales;
double txtTtlSales = 0.00;
double txtAvgSale;
double txtCommDue = 0.00;
double txtCommRate = 0.035;
bool txtBonus = false;
double txtBonusAmt = 0.00;
double ttlCommDue;
Console.WriteLine("enter amt");
txtSaleAmt = Console.ReadLine();
//Validation to perform
if (validateInput(txtSaleAmt))
{
// convert string
addingSales = Convert.ToInt32(Convert.ToDouble(txtSaleAmt));
Console.WriteLine("amount is {0}", txtSaleAmt);
txtTtlSales += addingSales;
txtNumSales++;
Console.WriteLine(" totalsales = {0}, adding = {1}, number sales = {2}", txtTtlSales, addingSales, txtNumSales);
txtAvgSale = (txtTtlSales / txtNumSales);
Console.WriteLine("average is {0}", txtAvgSale);
if (txtTtlSales <= 500.00)
{
txtCommRate = 0.035;
}
else if (txtTtlSales <= 999.99)
{
txtCommRate = 0.04;
}
else
{
txtCommRate = 0.05;
}
txtCommDue += (txtCommRate * addingSales);
Console.WriteLine("commission due is {0} and rate is {1} and average is {2}", txtCommDue, txtCommRate, txtAvgSale);
if (txtCommRate == 0.04)
{
txtBonus = true;
txtBonusAmt = 25.00;
ttlCommDue = (txtCommDue + txtBonusAmt);
}
else if (txtCommRate == 0.05)
{
txtBonus = true;
txtBonusAmt = 200.00;
ttlCommDue = (txtCommDue + txtBonusAmt);
}
else
{
txtBonus = false;
ttlCommDue = txtCommDue;
}
txtCommDue += txtBonusAmt;
Console.WriteLine("commission due is {0}", txtCommDue);
}
}
// 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);
}
}
}