Im trying to make a small window forms app that will:
1. when the user inputs a decimal value in the subtotal textbox and the person hits the calculate button- it will display in the total textbox
2. when the user inputs a new value in the subtotal textbox it adds it to the previous total and displays the new total in its total textbox ... and so forth.
3. the values must then go into an array named 'totals' that has a cap of 10 values.
4. when the user hits the exit button, a message box should appear with all amounts entered- any totals entered as 0 should not display and then the program should exit- so
if the user inputs 10, 0, 35, 90, 45, 0, 10 then the message box should display 10 (newline) 35 (newline) 90 (newline) 45 (newline) 10.
5. if there is more than 10 values entered(including 0 values) it should throw an exception saying that there is an overflowexception- then display all previous entered
values (except 0 values) in a the message box- then the program should exit.
right now im stuck on how the values are inputted into the totals array.
how do I do that please?
the controls are as follows:
lblSubtotal = label
txtSubtotal = text box
lblTotal = label
txtTotal = text box (disabled so the user cant change the value in it)
btnCalculate = button
btnExit = button
I have some blocked out code... and some code to display the values - but all it throws out is the last entered values 10 times- probably cause I'm doing something wrong
So far its been frustrating. Thanks again.
Sorry I'm still a newbie lol
1. when the user inputs a decimal value in the subtotal textbox and the person hits the calculate button- it will display in the total textbox
2. when the user inputs a new value in the subtotal textbox it adds it to the previous total and displays the new total in its total textbox ... and so forth.
3. the values must then go into an array named 'totals' that has a cap of 10 values.
4. when the user hits the exit button, a message box should appear with all amounts entered- any totals entered as 0 should not display and then the program should exit- so
if the user inputs 10, 0, 35, 90, 45, 0, 10 then the message box should display 10 (newline) 35 (newline) 90 (newline) 45 (newline) 10.
5. if there is more than 10 values entered(including 0 values) it should throw an exception saying that there is an overflowexception- then display all previous entered
values (except 0 values) in a the message box- then the program should exit.
right now im stuck on how the values are inputted into the totals array.
how do I do that please?
the controls are as follows:
lblSubtotal = label
txtSubtotal = text box
lblTotal = label
txtTotal = text box (disabled so the user cant change the value in it)
btnCalculate = button
btnExit = button
I have some blocked out code... and some code to display the values - but all it throws out is the last entered values 10 times- probably cause I'm doing something wrong
So far its been frustrating. Thanks again.
Sorry I'm still a newbie lol
C#:
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ArrayTotal
{
public partial class frmTotals : Form
{
public frmTotals()
{
InitializeComponent();
}
decimal subtotal = 0m;
decimal total = 0m;
const int MaxCount = 10;
decimal[] totals = new decimal[MaxCount];
private void btnCalculate_Click(object sender, EventArgs e)
{
subtotal = Decimal.Parse(txtSubtotal.Text);
total += subtotal;
txtTotal.Text = total.ToString("c");
for (int i = 0; i < totals.Length; i++)
totals[i] = subtotal;
/*
for (int i = 0; i < totals.Length; i++)
txtTotal.Text = subtotal.ToString();
txtSubtotal.Focus();
*/
}
private void btnExit_Click(object sender, EventArgs e)
{
string totalsString = "";
for (int i = 0; i < totals.Length; ++i)
totalsString += totals[i] + "\n";
MessageBox.Show(totalsString, "Sales Totals");
this.Close();
}
}
}
Last edited: