using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace CS12
{
public partial class frmCS12 : Form
{
public frmCS12()
{
InitializeComponent();
}
const int cintARRAY_SIZE = 10;
decimal[] cdecId = new decimal[cintARRAY_SIZE];
string[] cstrName = new string[cintARRAY_SIZE];
string[] cstrCode = new string[cintARRAY_SIZE];
decimal[] cdecRate = new decimal[cintARRAY_SIZE];
int cintNumberOfCostumers;
decimal[] cdecRATE_VALUE = new decimal[] { 0.03M, 0.05M, 0.10M, 0.00M };
string[] cstrCODE_LETTER = new string[] { "A", "F", "S", "X" };
private void btnLoadArrays_Click(object sender, EventArgs e)
{
int i = 0;
try
{
FileStream idFile = new FileStream("cs12.txt", FileMode.Open);
StreamReader idStreamReader = new StreamReader(idFile);
while (idStreamReader.Peek() != -1)
{
if (i < cdecId.Length)
{
cdecId[i] = decimal.Parse(idStreamReader.ReadLine());
cstrName[i] = idStreamReader.ReadLine();
cstrCode[i] = idStreamReader.ReadLine();
i++;
}
else
{
MessageBox.Show
("Error: Notify Programmer Array Size Exceeded. ",
"Array Size Exceeded", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
break;
}
}
idFile.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error Opening File. Data not loaded " + ex.Message,
"File Not Found",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
cintNumberOfCostumers = i;
assignDiscountRate();
displayArrays();
btnLoadArrays.Enabled = false;
}
void assignDiscountRate()
{
int s;
int g;
for (s = 0; s < cintNumberOfCostumers; s++)
{
for (g = 0; g <= cdecRATE_VALUE.GetUpperBound(0); g++)
{
if (cdecRate[s] >= cdecRATE_VALUE[g])
{
cstrCode[s] = cstrCODE_LETTER[g];
break;
}
}
}
}
void displayArrays()
{
int i;
lstId.Items.Clear();
lstName.Items.Clear();
lstCode.Items.Clear();
lstRate.Items.Clear();
for (i = 0; i < cintNumberOfCostumers; i++)
{
lstId.Items.Add(cdecId[i]);
lstName.Items.Add(cstrName[i]);
lstCode.Items.Add(cstrCode[i]);
lstRate.Items.Add(cdecRate[i].ToString("N2"));
}
}
private void btnSortById_Click(object sender, EventArgs e)
{
}
void swapArrayValues(int i, int intMinSubscript)
{
}
private void btnSortByName_Click(object sender, EventArgs e)
{
}
private void btnSearchByName_Click(object sender, EventArgs e)
{
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Displaying array problem
Page 1 of 14 Replies - 205 Views - Last Post: 26 November 2011 - 01:39 PM
#1
Displaying array problem
Posted 23 November 2011 - 12:28 AM
I seem to be having a problem with the function void assignDiscountRate, If I comment that part out I can get the discount code to display properly and the rate displays as 0.00, but when I try to incorpotate it the discount code change from the assigned value to X and the rate remains 0.00, any ideas on what I might be doing wrong?
Replies To: Displaying array problem
#2
Re: Displaying array problem
Posted 23 November 2011 - 05:27 AM
please post the values of your cs12.txt file
#3
Re: Displaying array problem
Posted 23 November 2011 - 12:03 PM
#4
Re: Displaying array problem
Posted 23 November 2011 - 03:51 PM
Try this
void assignDiscountRate()
{
int s;
int g;
for (s = 0; s < cintNumberOfCostumers; s++)
{
for (g = 0; g <= cdecRATE_VALUE.GetUpperBound(0); g++)
{
if (cstrCODE_LETTER[g] == cstrCode[s]) {
cdecRate[s] = cdecRATE_VALUE[g];
break;
}
}
}
}
#5
Re: Displaying array problem
Posted 26 November 2011 - 01:39 PM
Sorry for the late replay but I did the changes it worked.
Thanks for the help!
Thanks for the help!
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|