10 answers

Write a program to calculate the amount of a server's tip given the amount of the bill and the percentage

Question:

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

Answers

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!.

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..

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..

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..

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..

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..

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

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

It's been a pleasure!.

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..

Similar Solved Questions

1 answer
Agagenow.com/ilrn/takeAssignment/takeCovalen [Review Topics] [Referent Give an IUPAC name for the compound beld Accepted names for branched...
agagenow.com/ilrn/takeAssignment/takeCovalen [Review Topics] [Referent Give an IUPAC name for the compound beld Accepted names for branched alkyl groups a isobutyl, sec-butyl, and tert-butyl. CH2C1 CH3CCH3 CH3 Submit Answer Retry Entire Group 8 more group attempts remaining...
1 answer
The loaded cab of an elevator has a mass of 2.50 × 103 kg and moves...
The loaded cab of an elevator has a mass of 2.50 × 103 kg and moves 205. m up the shaft in 26.0 s at constant speed. At what average rate does the force from the cable do work on the cab?...
1 answer
Which of the following is characteristic of a perfectly competitive firm's demand curve? it is a...
Which of the following is characteristic of a perfectly competitive firm's demand curve? it is a horizontal line drawn at the market price since the firm is a price taker it is perfectly inelastic since the firm is a price taker its marginal revenue is always greater than the price O it is the s...
1 answer
3. Consider the following three subsets of the space of functions. Two of them are vector...
3. Consider the following three subsets of the space of functions. Two of them are vector spaces, and the other one is not a vector a space. Identify which subset isn't a vector space and explain how you know it isn't a vector space. V1. The set which contains only the constant polynomial p(...
1 answer
In the competitive market model, if the income elasticity of demand for a commodity is 07,...
In the competitive market model, if the income elasticity of demand for a commodity is 07, a fall in consumers' incomes of 10% will: (a) shift the demand curve for the commodity to the right X (b) shift the demand curve for the commodity to the left (c) reduce the quantity demanded by 7% (d) red...
1 answer
Zebra micro-devices, Inc. is considering an investment in new equipment that will cost $200,000 and is...
Zebra micro-devices, Inc. is considering an investment in new equipment that will cost $200,000 and is estimated to provide the following annual savings over its 5-year life: What is the internal rate of return associated with the new equipment? Should the company acquire the new equipment if it c...
1 answer
Two charges of magnitude |?| = 10 ?? are separated by a distance of 10 ??...
Two charges of magnitude |?| = 10 ?? are separated by a distance of 10 ?? along a horizontal axis. What is the potential as well as the magnitude and direction of the electric field at the midpoint between the two charges if a) both charges are positive and b) the left charge is positive and the rig...
1 answer
Please reply fast for a thumbs up?? Every classroom in Building A has 4 windows, ML25...
please reply fast for a thumbs up?? Every classroom in Building A has 4 windows, ML25 is a classroom in building A hence it has 4 windows. What type of reasoning is this? 3 1) Induction 6 2) None of the above 3) Deduction 4) Inaccurate Information 2 5 Question 36 (1 point) You are owner of a Groc...
1 answer
How do you differentiate #g(y) =(4x-5)(x-5) # using the product rule?
How do you differentiate #g(y) =(4x-5)(x-5) # using the product rule?...
1 answer
1) Water is a polar molecule. There is an effective accumulation of negative charge near the...
1) Water is a polar molecule. There is an effective accumulation of negative charge near the oxygen atom and an effective lack of negative charge ( positive charge) near each of the hydrogen atoms. The molecule is triangular in shape, as diagramed below, with the angle near the oxygen vertex equal t...
1 answer
. Fill in the missing particle in each of the following equations: (a) _________ 15866 Dy...
. Fill in the missing particle in each of the following equations: (a) _________ 15866 Dy + 0+1e (b) 24294Pu ________ + 23892U?...
1 answer
Problem 2 (course objective # 3, and 7): A laboratory consolidation test was performed on a...
Problem 2 (course objective # 3, and 7): A laboratory consolidation test was performed on a specimen from the middle of the clay layer shown below, with the test results tabulated below. Determine pe, OCR, Cr field, and Ce field; include plots and supporting calculations. Pay attention to the units ...
1 answer
C. Show how this note would be reported on Stephen Walker Company's December 31, Balance Sheet....
c. Show how this note would be reported on Stephen Walker Company's December 31, Balance Sheet. 6. Luke Alvez Corporation issued $200,000 of 9 % bonds on November 1, 2016, due on November 1, 2021. The interest is to be paid twice a year on May 1 and November 1 The bonds were sold to yield 10% ef...
1 answer
The centroid of a triangle lies at the intersection of the triangle's medians, because it lies one-third of the way from each side towards the opposite vertex. Use this result to find the centroi...
The centroid of a triangle lies at the intersection of the triangle's medians, because it lies one-third of the way from each side towards the opposite vertex. Use this result to find the centroid of the triangle whose vertices appear as following. (O,0) (4,0) (2,8) 3.4) ㅇ (2.3) (2.16) T...
1 answer
Create a complete ERD for the problem described in problem ch team those cond Identif ....
Create a complete ERD for the problem described in problem ch team those cond Identif . Identify . Identif . Identif PLAY . Draw . Draw Part 2 Design Concepts blems 1. Use the following business rules to create a Crow's Foot ERD. Write all appropriate connectivities and cardinalities in the ...
2 answers
Evaluate the indefinite integral:∫sqrt(10x−x^2)dx ?
Evaluate the indefinite integral:∫sqrt(10x−x^2)dx ?...