none
Pennies for pay RRS feed

  • Question

  • Create an application that allows the user to select or enter into a combo box the number of days a person will work, and calculates the total amount of pay she will receive over that period of time.
    Salary is one penny the first day, two pennies the second day, four pennies the third say, and continuing to double each day.
     This is what I have so far but I cant figure out how to be able to enter a value in as well as select one

    private Sub btnDays_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
            Dim Days As Integer
            Days = 1
            Dim combo As Integer
            combo = CInt(cboDays.SelectedItem)
            Dim Pennies As Integer
            Pennies = 1

            For Days = 1 To combo
                Pennies = Pennies * 2
            Next Days
            lblTotal.Text = Pennies.ToString()

        End Sub
    Monday, April 2, 2018 7:00 PM

All replies

  • Monday, April 2, 2018 7:00 PM
  • If they work three days then will they get a total of four pennies or is four pennies just for the third day? That is not clear in the description. Your instructor should have explained the description but if not then you need to get clarification.

    I don't understand what you mean by "how to be able to enter a value". I don't know if you are referring to something you do in the designer for the form or if it is something you do as a user of the form or if it is something you need to do in your source code.



    Sam Hobbs
    SimpleSamples.Info

    Monday, April 2, 2018 7:29 PM
  • Hi

    This snippet might help you, but, be aware of the limits of numerical calculations.

    2 ^ (CInt(ComboBox1.SelectedItem) - 1)


    Regards Les, Livingston, Scotland


    • Edited by leshay Monday, April 2, 2018 7:45 PM
    Monday, April 2, 2018 7:44 PM
  • This is what I have so far but I cant figure out how to be able to enter a value in as well as select one

    See here:
    https://msdn.microsoft.com/en-us/library/system.windows.forms.combobox(v=vs.110).aspx

    "The DropDownStyle property specifies whether the list is always displayed or whether the list is displayed in a drop-down. The DropDownStyle property also specifies whether the text portion can be edited. See ComboBoxStyle for the available settings and their effects."

    Monday, April 2, 2018 9:16 PM
  •  This is what I have so far but I cant figure out how to be able to enter a value in as well as select one

    private Sub btnDays_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
    ...
            combo = CInt(cboDays.SelectedItem)
    ...    End Sub

    Use cobDays.Text instead of SelectedItem.  Text will always return whatever is displayed, regardless of whether it was selected from the dropdown list or typed in directly.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    Monday, April 2, 2018 9:41 PM
    Moderator
  • If they work three days then will they get a total of four pennies or is four pennies just for the third day? That is not clear in the description. ...

    Is the old doubling-salary riddle - do you take a "big" salary up front or start with a penny and let it double?

    The rules are in the text the OP posted:

    "Salary is one penny the first day, two pennies the second day, four pennies the third day, and continuing to double each day."


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Monday, April 2, 2018 9:44 PM
    Moderator
  • The rules are in the text the OP posted:

    "Salary is one penny the first day, two pennies the second day, four pennies the third day, and continuing to double each day."

    That is ambiguous to me in the manner I described. It does not say "total salary" or "daily salary". If instead of "one penny the first day" it said "one penny for the first day" then that would be clear. Most people are happy to provide clarification of things like that.


    Sam Hobbs
    SimpleSamples.Info

    Tuesday, April 3, 2018 12:20 AM
  • Hi,

    As some people mentioned, your description is ambiguous. If you provide more samples, we can understand what you want to achieve.

    days -- Total Pay
    1 -- 1
    2 -- 2
    3 -- 4
    4 -- ??
    5 -- ??
    6 -- ??            

    Regards, 

    Ashidacchi -- http://hokusosha.com/

    • Edited by Ashidacchi Tuesday, April 3, 2018 1:38 AM
    Tuesday, April 3, 2018 1:38 AM
  • As some people mentioned, your description is ambiguous.

    It's not ambiguous. "...the number of days a person will work, and calculates the total amount of pay she will receive over that period of time." [emphasis added].

    Tuesday, April 3, 2018 1:55 AM
  • Hi,

    I made a sample that calculates Total Pay in two ways.
        

    Code in [Calculate] button:
    ' ---[Calculate]
    Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
    	If (Me.cmbDays.Text = "") Then
    		MessageBox.Show("Input Days worked")
    	Else
    		Select Case Me.cmbDays.Text
    			Case = "1"
    				Me.txtTotal.Text = "1"
    			Case = "2"
    				Me.txtTotal.Text = "2"
    			Case Else
    				If (Me.rbtMultiple.Checked) Then
    					Me.txtTotal.Text = ((CInt(Me.cmbDays.Text) - 1) * 2).ToString
    				Else
    					Me.txtTotal.Text = ((CInt(Me.cmbDays.Text) - 1) ^ 2).ToString
    				End If
    		End Select
    	End If
    End Sub
    Anyway, I hope you will provide more samples over thee days.


    Regards,

    Ashidacchi -- http://hokusosha.com/

    Tuesday, April 3, 2018 2:08 AM
  • It's not ambiguous. "...the number of days a person will work, and calculates the total amount of pay she will receive over that period of time." [emphasis added].

    Yes, that part is not ambiguous. You are commenting on the wrong part for the purpose of arguing something that has already been said and replied to.

    If you have some relevant help for AsherBeane then provide it. You have helped with the drop-down and if you have something to contribute with the calculation too then I assume AsherBeane will appreciate it. If you are correct about the calculation then show you do with a response that helps AsherBeane.

    Your understanding might be totally accurate. I am not you; I prefer to get clarification first.



    Sam Hobbs
    SimpleSamples.Info

    Tuesday, April 3, 2018 2:17 AM
  • Yes, that part is not ambiguous.

    Neither is the question: "I cant figure out how to be able to enter a value in as well as select one".  That has been answered.  OP doesn't want more people trying to show how they can code a simple introductory exercise. The problem is fixed in the Designer.

    Tuesday, April 3, 2018 3:23 AM