4 Replies - 344 Views - Last Post: 26 November 2011 - 01:39 PM Rate Topic: -----

#1 shango11  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 78
  • Joined: 06-July 11

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?
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();
        }

    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: Displaying array problem

#2 JHol  Icon User is offline

  • New D.I.C Head

Reputation: 14
  • View blog
  • Posts: 45
  • Joined: 10-February 11

Re: Displaying array problem

Posted 23 November 2011 - 05:27 AM

please post the values of your cs12.txt file
Was This Post Helpful? 1
  • +
  • -

#3 shango11  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 78
  • Joined: 06-July 11

Re: Displaying array problem

Posted 23 November 2011 - 12:03 PM

View PostJHol, on 23 November 2011 - 05:27 AM, said:

please post the values of your cs12.txt file


3030
Johnson
F
1010
Smith
S
4040
Lopez
A
6060
Sailor
X
2020
Davis
F
5050
Jones
S
Was This Post Helpful? 0
  • +
  • -

#4 JHol  Icon User is offline

  • New D.I.C Head

Reputation: 14
  • View blog
  • Posts: 45
  • Joined: 10-February 11

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;
                    }
               }
            }
        }


Was This Post Helpful? 1
  • +
  • -

#5 shango11  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 78
  • Joined: 06-July 11

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!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1