using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace CoinsExercise12StephenBarDev
{
    public partial class FrmStephensCoinage : Form
    {

        Array ValueOfCoins = Array.CreateInstance(typeof(String), 101);
                  
        double CoinInput;
    

        public FrmStephensCoinage()
        {
            InitializeComponent();
            ValueOfCoins.SetValue("0.00", 0);
            ValueOfCoins.SetValue("0.01",1);
            ValueOfCoins.SetValue("0.02",2);
            ValueOfCoins.SetValue("0.03",3);
            ValueOfCoins.SetValue("0.04", 4);
            ValueOfCoins.SetValue("0.05", 5);
            ValueOfCoins.SetValue("0.06", 6);
            ValueOfCoins.SetValue("0.07", 7);
            ValueOfCoins.SetValue("0.08", 8);
            ValueOfCoins.SetValue("0.09", 9);
            ValueOfCoins.SetValue("0.10", 10);
            ValueOfCoins.SetValue("0.11", 11);
            ValueOfCoins.SetValue("0.12", 12);
            ValueOfCoins.SetValue("0.13", 13);
            ValueOfCoins.SetValue("0.14", 14);
            ValueOfCoins.SetValue("0.15", 15);
            ValueOfCoins.SetValue("0.16", 16);
            ValueOfCoins.SetValue("0.17", 17);
            ValueOfCoins.SetValue("0.18", 18);
            ValueOfCoins.SetValue("0.19", 19);
            ValueOfCoins.SetValue("0.20", 20);
            ValueOfCoins.SetValue("0.21", 21);
            ValueOfCoins.SetValue("0.22", 22);
            ValueOfCoins.SetValue("0.23", 23);
            ValueOfCoins.SetValue("0.24", 24);
            ValueOfCoins.SetValue("0.25", 25);
            ValueOfCoins.SetValue("0.26", 26);
            ValueOfCoins.SetValue("0.27", 27);
            ValueOfCoins.SetValue("0.28", 28);
            ValueOfCoins.SetValue("0.29", 29);
            ValueOfCoins.SetValue("0.30", 30);
            ValueOfCoins.SetValue("0.31", 31);
            ValueOfCoins.SetValue("0.32", 32);
            ValueOfCoins.SetValue("0.33", 33);
            ValueOfCoins.SetValue("0.34", 34);
            ValueOfCoins.SetValue("0.35", 35);
            ValueOfCoins.SetValue("0.36", 36);
            ValueOfCoins.SetValue("0.37", 37);
            ValueOfCoins.SetValue("0.38", 38);
            ValueOfCoins.SetValue("0.39", 39);
            ValueOfCoins.SetValue("0.40", 40);
            ValueOfCoins.SetValue("0.41", 41);
            ValueOfCoins.SetValue("0.42", 42);
            ValueOfCoins.SetValue("0.43", 43);
            ValueOfCoins.SetValue("0.44", 44);
            ValueOfCoins.SetValue("0.45", 45);
            ValueOfCoins.SetValue("0.46", 46);
            ValueOfCoins.SetValue("0.47", 47);
            ValueOfCoins.SetValue("0.48", 48);
            ValueOfCoins.SetValue("0.49", 49);
            ValueOfCoins.SetValue("0.50", 50);
            ValueOfCoins.SetValue("0.51", 51);
            ValueOfCoins.SetValue("0.52", 52);
            ValueOfCoins.SetValue("0.53", 53);
            ValueOfCoins.SetValue("0.54", 54);
            ValueOfCoins.SetValue("0.55", 55);
            ValueOfCoins.SetValue("0.56", 56);
            ValueOfCoins.SetValue("0.57", 57);
            ValueOfCoins.SetValue("0.58", 58);
            ValueOfCoins.SetValue("0.59", 59);
            ValueOfCoins.SetValue("0.60", 60);
            ValueOfCoins.SetValue("0.61", 61);
            ValueOfCoins.SetValue("0.62", 62);
            ValueOfCoins.SetValue("0.63", 63);
            ValueOfCoins.SetValue("0.64", 64);
            ValueOfCoins.SetValue("0.65", 65);
            ValueOfCoins.SetValue("0.66", 66);
            ValueOfCoins.SetValue("0.67", 67);
            ValueOfCoins.SetValue("0.68", 68);
            ValueOfCoins.SetValue("0.69", 69);
            ValueOfCoins.SetValue("0.70", 70);
            ValueOfCoins.SetValue("0.71", 71);
            ValueOfCoins.SetValue("0.72", 72);
            ValueOfCoins.SetValue("0.73", 73);
            ValueOfCoins.SetValue("0.74", 74);
            ValueOfCoins.SetValue("0.75", 75);
            ValueOfCoins.SetValue("0.76", 76);
            ValueOfCoins.SetValue("0.77", 77);
            ValueOfCoins.SetValue("0.78", 78);
            ValueOfCoins.SetValue("0.79", 79);
            ValueOfCoins.SetValue("0.80",80);
            ValueOfCoins.SetValue("0.81", 81);
            ValueOfCoins.SetValue("0.82", 82);
            ValueOfCoins.SetValue("0.83", 83);
            ValueOfCoins.SetValue("0.84", 84);
            ValueOfCoins.SetValue("0.85", 85);
            ValueOfCoins.SetValue("0.86", 86);
            ValueOfCoins.SetValue("0.87", 87);
            ValueOfCoins.SetValue("0.88", 88);
            ValueOfCoins.SetValue("0.89", 89);
            ValueOfCoins.SetValue("0.90", 90);
            ValueOfCoins.SetValue("0.91", 91);
            ValueOfCoins.SetValue("0.92", 92);
            ValueOfCoins.SetValue("0.93", 93);
            ValueOfCoins.SetValue("0.94", 94);
            ValueOfCoins.SetValue("0.95", 95);
            ValueOfCoins.SetValue("0.96", 96);
            ValueOfCoins.SetValue("0.97", 97);
            ValueOfCoins.SetValue("0.98", 98);
            ValueOfCoins.SetValue("0.99", 99);
            ValueOfCoins.SetValue("1.00", 100);
        }

        private void BtnCalculate_Click(object sender, EventArgs e)
        {

            CoinInput = double.Parse(TbValueOfCoinage.Text);

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(0)))
            {
                MessageBox.Show("Enter At least A penny");

            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(1)))
            {
                LblTotalOf1s.Text = 1.ToString();

            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(2)))
            {
                LblTotalOf2s.Text = 1.ToString();

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(3)))
            {
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
            }


            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(4)))
            {
                LblTotalOf2s.Text = 2.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(5)))
            {
                LblTotalOf5s.Text = 1.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(6)))
            {
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(7)))
            {
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(8)))
            {
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(9)))
            {
                LblTotalOf2s.Text = 2.ToString();
                LblTotalOf5s.Text = 1.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(10)))
            {
                LblTotalOf10s.Text = 1.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(11)))
            {
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(12)))
            {
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(13)))
            {
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(14)))
            {
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf2s.Text = 2.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(15)))
            {
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(16)))
            {
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
               LblTotalOf5s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(17)))
            {
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(18)))
            {
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(19)))
            {
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf2s.Text = 2.ToString();
                LblTotalOf5s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(20)))
            {
                LblTotalOf20s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(21)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
            
           }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(22)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
               
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(23)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(24)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf2s.Text = 2.ToString();

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(25)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(26)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(27)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(28)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(29)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 2.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(30)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf10s.Text = 1.ToString();
                
            }


            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(31)))
            {
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
            
           }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(32)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                LblTotalOf10s.Text = 1.ToString();
               
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(33)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                LblTotalOf10s.Text = 1.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue (34)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf2s.Text = 2.ToString();
                LblTotalOf10s.Text = 1.ToString();

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(35)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf10s.Text = 1.ToString();

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(36)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf10s.Text = 1.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(37)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(38)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(39)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf2s.Text = 2.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(40)))
            {
                LblTotalOf20s.Text = 2.ToString();
              
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(41)))
            {
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(42)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(43)))
            {
                LblTotalOf20s.Text = 2.ToString();
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(44)))
            {
                LblTotalOf20s.Text = 2.ToString();
                LblTotalOf2s.Text = 2.ToString();
               

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(45)))
            {
                LblTotalOf20s.Text = 2.ToString();
                LblTotalOf5s.Text = 1.ToString();
                

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(46)))
            {
                LblTotalOf20s.Text = 2.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
                
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(47)))
            {
                LblTotalOf20s.Text = 2.ToString();
                
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(48)))
            {
                LblTotalOf20s.Text = 2.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                
                LblTotalOf1s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(49)))
            {
                LblTotalOf20s.Text = 2.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 2.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(50)))
            {
                LblTotalOf50s.Text = 1.ToString();
            }
 //  --------------------------------------------------------------------------------------- 1-50p
       

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(51)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(52)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(53)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(54)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf2s.Text = 2.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(55)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(56)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
               LblTotalOf5s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue (57)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(58)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(59)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf2s.Text = 2.ToString();
                LblTotalOf5s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(60)))
            {
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(61)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf10s.Text = 1.ToString();
            
           }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(62)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
               
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(63)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(64)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf2s.Text = 2.ToString();

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(65)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(66)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(67)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(68)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(69)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 2.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(70)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();
                
            }


            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(71)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
            
           }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(72)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();
               
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(73)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue (74)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf2s.Text = 2.ToString();
                LblTotalOf50s.Text = 1.ToString();

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(75)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(76)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue (77)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(78)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(79)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf2s.Text = 2.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(80)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf10s.Text = 1.ToString();
              
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(81)))
            {
                LblTotalOf10s.Text = 1.ToString();
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(82)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(83)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(84)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf2s.Text = 2.ToString();
               

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(85)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(86)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();
                
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(87)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(88)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(89)))
            {
                LblTotalOf20s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 2.ToString();
                LblTotalOf50s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(90)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf20s.Text = 2.ToString();
            }


            

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(91)))
            {
                
                LblTotalOf20s.Text = 2.ToString();
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(92)))
            {
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf20s.Text = 2.ToString();
                LblTotalOf2s.Text = 1.ToString();
                

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(93)))
            {
                LblTotalOf20s.Text = 2.ToString();
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(94)))
            {
                LblTotalOf20s.Text = 2.ToString();
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf2s.Text = 2.ToString();
               

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(95)))
            {
                LblTotalOf20s.Text = 2.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();

            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(96)))
            {
                LblTotalOf20s.Text = 2.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();
                
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(97)))
            {
                LblTotalOf20s.Text = 2.ToString();
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(98)))
            {
                LblTotalOf20s.Text = 2.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 1.ToString();
                LblTotalOf50s.Text = 1.ToString();
                LblTotalOf1s.Text = 1.ToString();
            }
            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(99)))
            {
                LblTotalOf20s.Text = 2.ToString();
                LblTotalOf5s.Text = 1.ToString();
                LblTotalOf2s.Text = 2.ToString();
                LblTotalOf50s.Text = 1.ToString();
            }

            if (CoinInput == Convert.ToDouble(ValueOfCoins.GetValue(100)))
            {
                LblTotalOf50s.Text = 2.ToString();
            }


            if (CoinInput > Convert.ToDouble(ValueOfCoins.GetValue(100)))
            {
                MessageBox.Show("Enter Currency less than 1.00");
                MessageBox.Show("Make Sure You use 1.00 or 0 in front of pence.");
            }


          //  ------------------------------------------- 50 to 10
        
            
                        }

                    
                
         

        private void BtnExit_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void BtnClear_Click(object sender, EventArgs e)
        {
            LblTotalOf50s.Text = 0.ToString();
            LblTotalOf2s.Text = 0.ToString();
            CoinInput = 0;
            LblTotalOf20s.Text = 0.ToString();
            LblTotalOf10s.Text = 0.ToString();
            LblTotalOf5s.Text = 0.ToString();
            LblTotalOf1s.Text = 0.ToString();
            TbValueOfCoinage.Focus();
            TbValueOfCoinage.Clear();
        }

        private void FrmStephensCoinage_Load(object sender, EventArgs e)
        {
        
        }

       
        }
    }

i want to know if there is another way of writing this program to

calculate and displays the minimum number of pennies, two pence coins, five pence coins, ten pence coins, twenty pence coins and fifty pence coins that add up to that amount.


possibly Using a loop to calculate the number of each coin that’s required. I think The loop should divide the remaining cents by each coin value, starting with the largest value. dominators.


any comments on this, please any help would be apprechiated.

written by stephen barratt.

Wow! Yes, there is definitely a better way to write that :)

Firstly, and these are moot points since your going to scrap that and start over (i hope), but you are storing your values as strings then converting them to doubles...why not just store them as an array of doubles? And if you absolutely requrie an array like that, you can create it in code far more easily:

Array ValueOfCoins = Array.CreateInstance(typeof(String), 101);
            for (int i = 0; i <= 100; i++)
            {
                double value = (double)i / (double)100;
                ValueOfCoins.SetValue(value.ToString(), i);
            }

As for the problem, you are right, you can do this calculation easily using some loops and a little logic. You will need to use modulus division here. Start with the largest denominator (50), calculate how many 50's go into your value. then use mod division remainder = inputValue % 50 to get the value of whats left.
Repeat the process on the remainder using the next largest denominator.

Wow is right! As Ryshad suggested, you could do this without the array altogether. However, if you must use an array as part of the requirements, I would suggest using an array to represent the monetary denominations instead of a 1 to 1 representation of 0.00 - 1.00. For example:

int[] denominations = 
            {
                1, // pennies
                2, // two pence
                5, // five pence
                10, // ten pence
                20, // twenty pence
                50 // fifty pence
            };

You could then incorporate that array with the modulo loop that Ryshad suggested to allocate each of the denominations.

Also, and as a side note, if you were to incorporate this array design and pass it into a method that uses the modulo loop design with the given array, your coin buckets could be made to be country/coin independent. However, you might need to make some adjustments to your form to make it independent as well. I wouldn't worry about this right now, but a way of thinking you can ponder a little...

Cheers!

Hmm. Okay Scrap and restart. Might make secound version. To show my working. Will look up soon.

Coin is okay but i need some help with spliting now. here is what i have its a bit jumbled. i want to take a name accountno and password from a client using one text box and split it the delimiter ,

my code before i added the char and the secound form loop allowed me to split it once but only at the last delimiter.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Exercise11
{
    public partial class FrmStephensBank : Form
    {
        //
        //string NameAccountPass;
     //   string[] SpiltForAccount;
  //      string[] SplitForPassword;


// when this was not here;
      //   public String[] Split(params char[] separator);
 
        public FrmStephensBank()
        {
            InitializeComponent();
        }

        private void BtnParse_Click(object sender, EventArgs e)
        {
// and this was not here.
            new Char[] { ',', ' ' };
        //    NameAccountPass = TbValueOfString.Text;
         //   SpiltForAccount = NameAccountPass.Split(',');
          //  SpiltForPassword = SpiltForAccount.Split(',');


         //   for (int i = 0; i < SpiltForAccount.Length; i++)
          // {

           //     lblAccountno.Text = SpiltForAccount[i] + "\n";
           // }
// and this was not here i could split it once.
            //     for (i = 0; i < SpiltForPassword.Length; i++)
            //  {
            //      LblPassword.Text = SpiltForPassword[i] + "\n";
            //  }

            //  }


        }

How can i do it to split it 3 times so i can place my results in a label??.

any help would be apprechiated.

links of use - snippets etc.

Firstly, since this is not related to your coin problem it should really be in a new thread. Not only does it prevent confusion, it also ensures you get the help you need ( especially if you give threads meaningful titles like "Help with splitting string" rather than "Help with C#").

As for your problem, why do you want them to type all three pieces of information in a single textbox? Its a validation nightmare, you are making the user responsible for using the correct delimiters, entering the correct information, entering ALL three pieces AND entering them in the right order.
The only thing the user should ever be responsible for is entering thier data correctly, and even then you should validate it and tell them if they made a mistake. I find it helps to assume i'm writing my programs for barely literate chimpanzees ;) Whilst you or i may know that the data has to be split by spaces or commas, a user wont necessarily have a full understanding. Far better to have three textboxes, one for each piece of data that can be validated and stored individually.

Comments
Great Help to BrightSolar.

i know it would be better to have 3 but its a mini assigment exercise and has to be in one text box.

i think i have to read the whole length of the textbox into a string then seperate it using a max length of name = 12, and when delimiter is found - read chracters before it into a seperate string.
declaring a max length for password and account number also.
its not really a problem of validating it, its the problem of how do i count
chracters backwards when a delimiter is reached and then take that value and store it in another string possibly using the stringTotal = str1 - str 2;

--------------------------------------------------------------------------------
Maybe it should have been a seperate topic but it would kinda be hard for me to keep track of it. Because i have lots of weblinks outside of folders. in favourites. more than 200... ---
----------------------------------------

ps i wanna sig this

I find it helps to assume i'm writing my programs for barely literate chimpanzees:icon_lol:

Edited 7 Years Ago by brightsolar: n/a

Firstly, you can sig it if you sign it ;)

As for the string, if the assignment stipulates you use a single textbox then thats fair enough. As long as you're aware that its far from an ideal way to do it.

To do it the way you said above you will need to us some of the string methods. Firstly, you can search for the delimiter using IndexOf, then extract the sections using Substring:

string inputString = "name,123:password"
int indexAt = inputString.IndexOf(",");
string name = inputString.Substring(0 , indexAt);
inputString = InputString.Substring(indexAt + 1);

the above example extracts the first part then removes it from the string.
If you have the same delimeter between each section you can use String.Split to divide the string into an array of substrings.

This question has already been answered. Start a new discussion instead.