6 Replies - 479 Views - Last Post: 18 February 2013 - 08:05 AM Rate Topic: -----

#1 Afrosephurai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 17-February 13

C#. Change Counter up to $1

Posted 17 February 2013 - 10:20 PM

I having an extra credit homework assignment, and I've been stuck for hours trying to find a way to display amount of changed enter. There are 4 field. Nickles, Quarters, Dimes, and Pennies. But I'm having trouble with the user input and and calculation.

Below is my code: (I'm a beginner so bare with me)

 
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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        const double dblnumberofPennies = 1;
        const double dblnumberofNickels = 5;
        const double dblnumberofDimes = 10;
        const double dblnumberofQuarters = 25;
        const double dblGoal = dblnumberofDimes + dblnumberofNickels + dblnumberofPennies + dblnumberofQuarters;
      
       
        public Form1()
        {
            InitializeComponent();
        }

        private void btnClear_Click(object sender, EventArgs e)
        //Clears user input from textboxes
        
        {
            txtPennies.Clear();
            txtDimes.Clear();
            txtNickels.Clear();
            txtQuarters.Clear();
            lblCount.Text = string.Empty;

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


            
            
                
        }

        private void txtQuarters_TextChanged(object sender, EventArgs e)
        {
            Console.ReadLine(); 
            
        }

        private void lblPennies_Click(object sender, EventArgs e)
        {

        }

        private void lblNickels_Click(object sender, EventArgs e)
        {

        }

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

        private void lblQuarters_Click(object sender, EventArgs e)
        {

        }

        private void txtNickels_TextChanged(object sender, EventArgs e)
        {

          
        }

        private void txtDimes_TextChanged(object sender, EventArgs e)
        {
            Console.ReadLine();
        }

        private void btnExit_Click(object sender, EventArgs e)
            //End application 
        {
            Application.Exit(); 
        }

       
        private void btnCount_Click(object sender, EventArgs e)
        // Calculate Currency
        {

            if (dblnumberofPennies == 100 ) MessageBox.Show("Congrats!");



            lblCount.Text = dblGoal.ToString(); 

              
        
        
        
        
        
        
        
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

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






Also attached is the unfinished application.

Is This A Good Question/Topic? 0
  • +

Replies To: C#. Change Counter up to $1

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,126
  • Joined: 18-April 07

Re: C#. Change Counter up to $1

Posted 17 February 2013 - 11:34 PM

When you are dealing with buttons and textboxes and such, you are not dealing with Console anymore. You are in a windows form application, not a console application.

So what you want to do is have the user enter some value in a textbox and then you read that textbox when the user clicks the button.

private void btnGetChange_Click(object sender, EventArgs e) {
     double result;

     if (Double.TryParse(textBox1.Text, out result)) {
                // Do stuff here like get number of quarters
                int quarters = (int)(result / .25);
      }
}



Here we are taking the value from our textbox and parsing it into a double value called "result". This variable is now a double so we can divide it by .25 and that will tell us the number of quarters fit into the result.

So play with the ideas here and you will be on the right track. (Hint: think about the modulus operator % to get a remainder of money that didn't fit evenly into quarters. This amount will then go to finding dimes, nickles and pennies)

:)
Was This Post Helpful? 0
  • +
  • -

#3 TheKirk  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 58
  • Joined: 10-February 13

Re: C#. Change Counter up to $1

Posted 17 February 2013 - 11:37 PM

You are trying to read input from the console while creating a Windows Form Application.

private void txtDimes_TextChanged(object sender, EventArgs e)
{
    Console.ReadLine();
}


You can retreive the text inside a textbox by using the <i>Text</i> property of a TextBox:

string Value = txtDimes.Text;


I assume you want to convert it to a double:

double Value = Convert.ToDouble(txtDimes.Text);

Was This Post Helpful? 0
  • +
  • -

#4 Afrosephurai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 17-February 13

Re: C#. Change Counter up to $1

Posted 17 February 2013 - 11:56 PM

So what exactly I am putting in the input elements?


 private void txtDimes_TextChanged(object sender, EventArgs e)
        {
            
            double Value = Convert.ToDouble(txtDimes.Text);
        }




That?

So what exactly I am putting in the input elements?


 private void txtDimes_TextChanged(object sender, EventArgs e)
        {
            
            double Value = Convert.ToDouble(txtDimes.Text);
        }




That?
Was This Post Helpful? 0
  • +
  • -

#5 Afrosephurai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 17-February 13

Re: C#. Change Counter up to $1

Posted 18 February 2013 - 12:15 AM

View PostMartyr2, on 17 February 2013 - 11:34 PM, said:

When you are dealing with buttons and textboxes and such, you are not dealing with Console anymore. You are in a windows form application, not a console application.

So what you want to do is have the user enter some value in a textbox and then you read that textbox when the user clicks the button.

private void btnGetChange_Click(object sender, EventArgs e) {
     double result;

     if (Double.TryParse(textBox1.Text, out result)) {
                // Do stuff here like get number of quarters
                int quarters = (int)(result / .25);
      }
}



Here we are taking the value from our textbox and parsing it into a double value called "result". This variable is now a double so we can divide it by .25 and that will tell us the number of quarters fit into the result.

So play with the ideas here and you will be on the right track. (Hint: think about the modulus operator % to get a remainder of money that didn't fit evenly into quarters. This amount will then go to finding dimes, nickles and pennies)

:)/>



Sorry, still a bit lost. :(
Was This Post Helpful? 0
  • +
  • -

#6 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 353
  • View blog
  • Posts: 1,512
  • Joined: 08-April 09

Re: C#. Change Counter up to $1

Posted 18 February 2013 - 01:54 AM

Have you tried consulting with your teacher first, BEFORE you ask a bunch of strangers on the internet :)
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5464
  • View blog
  • Posts: 11,731
  • Joined: 02-June 10

Re: C#. Change Counter up to $1

Posted 18 February 2013 - 08:05 AM

I'm with Michael on this. You're in over your head. You've missed some vital bits and need to back up a chapter or 3 and go over the material again until it makes sense.


"I don't know where to start" - This usually means you should go back to your instructor and admit you are this lost. Don't bluff your way through this course thinking that by chapter 10 it will all suddenly snap into place and become clear. It won't. Unlike history class where chapter 1 might be 17th century England and chapter 2 might be World War II, giving you a fresh start - Coding builds upon the lessons of the previous chapter. You have to use lesson 1 material to succeed in lesson 2. Chapter 10 builds upon and uses material from chapter 9. If you let your pride get in the way you will be too lost to recover and have wasted thousands of dollars in tuition.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1