programming

posted by .

write a program to calculate the amount of a server's tip given the amount of the bill and the percentage tip ovtained via input dialog boxes. The output should be a complete sentence that reiterates the inputs and gives the resulting tip.

here is my attempt:

Public Class frmTip

Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click
Dim billAmount As Double
Dim percent, tip As Double
billAmount = CDbl(InputBox("Amount of Bill"))
percent = CDbl(InputBox("Amount of Tip"))
tip = billAmount * percent / 100
txtOutput.Text = CDbl(Math.Round(tip, 2))
txtOutput.Text = "A percent tip on bill is tip"
End Sub
End Class

  • programming -

    It's been a long time since I looked at programming, but let me guess. All you are getting is something that says, "A percent tip on bill is tip."

    Notice what you put in quotation marks.

    Again....I could be way off on this. It's been YEARS!

  • programming -

    No you are right. But I'm having trouble getting the correct coding for that step. Any ideas?

  • programming -

    It's from this line:
    txtOutput.Text = "A percent tip on bill is tip"

    It should say:
    txtOutput.Text = "A percent tip on bill is " + tip

    I don't remember if you need a + or & or what exactly it is. I think it's a +.

    Try that. Again....sorry if I am wrong. It's been a long time.

    What is inside quotations will be quoted directly. Things outside the quotation marks are variables. That will cause whatever "tip" is to be printed.

    I don't know if your math is right. First see if you can get the program right, then you can fix the rest.

  • programming -

    Matt is right, you can use both + and & to concatenate strings, if they are both strings.
    With the +, there is a danger that arithmetic operations will be performed before output, while the & will coerce any numeric variables to strings before output, so & is generally safer.

    You can do something like:
    txtOutput.text = CDbl(percent) & " percent tip on a bill of " & CDbl(bill) & " is " & CDbl(tip) & " dollars".

    You will find a whole lot of decimal figures after the decimal point. You will need to do some formatting, depending on what you have done in your course. One way is to use
    String.Format("{0:c}", bill)
    to replace bill. "c" is the currency option.
    You can also use a single String.Format() statement to output all three variables (percent, bill and tip) together with the embedded text.

    I do not have VB.net to test it out, but tell us if you have difficulties.

  • programming -

    Well I used & instead of + which is what we have learned in class. I'm not sure about the string operation.
    The program works. The problem I am having is having the currency appear properly. The output should appear as follows: A 15% tip on $20.00 is $3.00, but my output appears as: A 15% tip on $20 is $3 Here's the program I have so far:

    Public Class frmTip

    Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click
    Dim billAmount, tip As Double
    Dim percent As Double
    billAmount = CStr(InputBox("Amount of Bill"))
    percent = CDbl(InputBox("Amount of Tip"))
    tip = billAmount * percent / 100
    txtOutput.Text = "A " & percent & "% tip on $" & billAmount & " is $" & tip
    End Sub
    End Class

    Thank you so much. You are very helpful.

  • programming -

    For the output, there may be a better way to do it, but the following works:

    txtOutput.Text = "A " & String.Format("{0:f0}", percent) & "% tip on " & String.Format("{0:c}", billAmount) & " is " & String.Format("{0:c}", tip)

    The "{0:f0}" tells the string.Format method to format the next parameter (percent) as a floating number with 0 digits after the decimal point.
    The "{0:c}" tells the string.Format method to format the next parameter (bill) as a monetary amount. The $ will be added if your locale uses dollars. Also, it will add the thousands separators, and 2 digits after the decimal point if this is what your locale defines.

    Try it and let us know if you need other information.

  • programming -

    Thank you so much for your help. It finally works. This is what I have:

    Public Class frmTip

    Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click
    Dim billAmount, tip As Double
    Dim percent As Double
    billAmount = CStr(InputBox("Amount of Bill"))
    percent = CDbl(InputBox("Amount of Tip"))
    tip = billAmount * percent / 100
    txtOutput.Text = "A " & percent & "% tip on " & FormatCurrency(billAmount) & " is " & FormatCurrency(tip)
    End Sub
    End Class

    I'll try your solution as well.

  • programming -

    Good job!

    If you want perfection, you can do some data checking, such as non-negative bill and percentage etc. and re-prompt for the correct values.

  • programming -

    Good idea I"ll do that. Thank you so much.

  • programming :) -

    It's been a pleasure!

  • computer support specialist -

    Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnterData.Click
    Dim billAmount, percent As String
    Dim tip As Double
    billAmount = CStr(InputBox("Amount of Bill"))
    percent = CStr(InputBox("Amount of Tip"))
    tip = billAmount * percent / 100
    txtBoxShow.Text = ("A " & percent & " % tip on " & FormatCurrency(billAmount) & " is " & FormatCurrency(tip))
    End Sub

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. CIS Design and Programming

    Design a program that calculates the total amount of a meal purchased at a restaurant. The program should ask the user to enter the charge for the food, and then calculate the amount of a 15 percent tip and a 7 percent sales tax. Display …
  2. Computer Programming Design

    I really need someone to help me with this.I post this last week and I did not respond to it hopefully someone will respond Design a program that calculates the total amount of a meal purchased at a restaurant. The program should ask …
  3. Programming

    Design a program that calculates the total amount of a meal purchased at a restaurant. The program should ask the user to enter the charge for the food, and the calculate the amount of a 15 percent tip and 7 percent sales tax. Display …
  4. Computer Visual Basics 2008

    This questions is from Chapter 5, #54) Write a program to compute tips for services rendered. The program should request th person's occupation, the amount of the bill, and the percentage tip as input and pass this informaiton to a …
  5. Visual Basics 2008

    This is a from chapter 3 #82. the problem is: Write a program to calculate the amount of a server's tip given the amount of the bill and the percentage tip obtained via imput dialog boxes. The output should be a complete sentence that …
  6. Programming

    Language - PYTHON Design a program that calculates the total amount of a meal purchased at a restaurant. The program should ask the user to enter the charge for the food, and then calculate the amount of a 15% tip and 7% sales tax. …
  7. Intro to programming

    Tip, Tax and Total question? Design a program that calculates the total amount of a meal purchased at a restaurant in raptor, the program has to ask user the charge of food, calculate the amount of a 15 percent tip, and 7 percent sales
  8. programming

    Assume the input to be the charge for the food, draw a flowchart that will compute the total amount of a meal purchased at a restaurant. The output should be the charge for the food, the amount of a 15 percent tip, the amount of the …
  9. intro to computer programming

    I need help with my Java homework! Write a program that calculates a customer's monthly bill. It should ask the user via dialog box to enter the letter of the package the customer has purchased (A, B, or C) and the number of hours …
  10. c programming

    write a program that computes tax and tip on a restaurant bill for a patron with rs.44.50 per meal charge.the tax should be 6.75 percent of the meal cost.the tip should be 15 percent of the total after adding the tax.display the meal …

More Similar Questions