when i hit the calculate button the number entered into the text box is calculate and then stored in an array (the array has five spaces allotted for the information )
after you have your five entries into the array you hit exit and it spits out in a message box the contence of the Array .(this should be all five calculated totals in the array)
what i am experiencing when i hit exit it displays the last total for all of the array no matter the other numbers entered
here is my code : -
using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data;
-
using System.Drawing;
-
using System.Linq;
-
using System.Text;
-
using System.Windows.Forms;
-
-
namespace InvoiceTotal
-
{
-
// This is the starting point for exercise 8-1 from
-
// "Murach's C# 2010" by Joel Murach
-
// (c) 2010 by Mike Murach & Associates, Inc.
-
// www.murach.com
-
-
public partial class frmInvoiceTotal : Form
-
{
-
-
-
-
-
public frmInvoiceTotal()
-
{
-
InitializeComponent();
-
invoiceTotals[0] = 0.0m;
-
invoiceTotals[1] = 0.0m;
-
invoiceTotals[2] = 0.0m;
-
invoiceTotals[3] = 0.0m;
-
invoiceTotals[4] = 0.0m;
-
}
-
-
// TODO: declare class variables for array and list here
-
decimal[] invoiceTotals = new decimal [5];
-
-
-
-
-
-
-
private void btnCalculate_Click(object sender, EventArgs e)
-
{
-
try
-
{
-
-
if (txtSubtotal.Text == "")
-
{
-
MessageBox.Show(
-
"Subtotal is a required field.", "Entry Error");
-
}
-
else
-
{
-
decimal subtotal = Decimal.Parse(txtSubtotal.Text);
-
if (subtotal > 0 && subtotal < 10000)
-
{
-
decimal discountPercent = 0m;
-
if (subtotal >= 500)
-
discountPercent = .2m;
-
else if (subtotal >= 250 & subtotal < 500)
-
discountPercent = .15m;
-
else if (subtotal >= 100 & subtotal < 250)
-
discountPercent = .1m;
-
decimal discountAmount = subtotal * discountPercent;
-
decimal invoiceTotal = subtotal - discountAmount;
-
-
discountAmount = Math.Round(discountAmount, 2);
-
invoiceTotal = Math.Round(invoiceTotal, 2);
-
-
txtDiscountPercent.Text = discountPercent.ToString("p1");
-
txtDiscountAmount.Text = discountAmount.ToString("c");
-
txtTotal.Text = invoiceTotal.ToString("c");
-
-
-
// TODO: Add invoice total to the array here
-
-
for (int i = 0; i < invoiceTotals.Length; i++)
-
{
-
invoiceTotals[i] = invoiceTotal;
-
-
}
-
-
-
}
-
else
-
{
-
MessageBox.Show(
-
"Subtotal must be greater than 0 and less than 10,000.",
-
"Entry Error");
-
}
-
}
-
}
-
catch (FormatException)
-
{
-
MessageBox.Show(
-
"Please enter a valid number for the Subtotal field.",
-
"Entry Error");
-
}
-
txtSubtotal.Focus();
-
}
-
-
private void btnExit_Click(object sender, EventArgs e)
-
{
-
// TODO: add code that displays dialog boxes here
-
-
string currentTotals = "";
-
for (int i = 0; i < invoiceTotals.Length; i++)
-
currentTotals += invoiceTotals[i].ToString("c") + "\n";
-
MessageBox.Show(currentTotals, "Order Totals");
-
-
-
this.Close();
-
}
-
-
private void frmInvoiceTotal_Load(object sender, EventArgs e)
-
{
-
-
}
-
-
}
-
}
-
2 2283
You are trying to concatenate a string value, in the below code that you have written. - string currentTotals = "";
If you really want to display the total. Try parsing it, or else instead of using string use decimal.
The problem is line 78. You assign the same value to every element in your array.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Aguilar, James |
last post by:
My previous example used the concept of a Shape class heirarchy, so I will
continue with that.
Suppose I have something like fifty different shapes, and I am trying to
instantiate one of them. ...
|
by: Geoff Cox |
last post by:
Hello
I have following type of code in the header
function pre_load_pics()
{
if (document.images)
{
var image1 = new Image(400,265);
image1.scr = "pic1.jpg";
|
by: Jens Mittag |
last post by:
Hi!
In my code, I have an array of a structure, which I want to save to a
binary file. When the array is just created, everything works fine, but
when I change contents of the array, saving...
|
by: Bala |
last post by:
Hi,
In my page there is 4 dropdown list boxes.when page loading that time i am
loading the nearly 3000 items array. so its taking too much time to load.
is it other way fill up the dropdown...
|
by: bobmct |
last post by:
Fellow PHP'ers;
I'm digging myself a hole on this one so I thought it has come to the
time when I must ask those who know.
I have what should be a simple question for loading, accessing and...
|
by: Miro |
last post by:
Im trying to store data as I would in some old language.
Old Example
//Create an array that holds 3 different variable types
TempArray := { { "Hello", 1, False }, { "Goodbye", 123, True } }
...
|
by: jhoff |
last post by:
So, I'm in a pickle...
Lets say I have a page: http://www.gen2host.com/discgolf/index.html
and on this page, there are a list of links. These links will be
generated by 5 pieces of data pulled...
|
by: Barkingmadscot |
last post by:
I am stuck, i can workout how to remove lines from an array
I have loading a text file (a Log), I know which lines a need, but
the logs can be upto 30K sometimes bigger. I found trying to...
|
by: =?Utf-8?B?cmF1bGF2aQ==?= |
last post by:
vs2008 c#
how can I load an array from XML?
lets say I have now
string arr = {23,32,45,34,21,23,243,45 }
I want to read the values from XML.
thanks
|
by: anfetienne |
last post by:
i have this code below that i made....it loads vars from txt file splits it then puts it into an array....once in an array it the brings the pics in from the array to create thumbnails and a larger...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |