3 Replies - 11321 Views - Last Post: 15 June 2009 - 01:58 AM Rate Topic: -----

#1 brianmen  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 39
  • Joined: 14-June 09

Creating Tip Calculator Program

Posted 14 June 2009 - 11:05 AM

Hi all. I started learning Python yesterday. I really like it, but I've run into a problem. I'm making a tip calculator program, but cannot seem to get it to work with decimal point numbers such as 12.55, 4.66, ect. Whole numbers such as 12, 55, 34 seem to work fine. Would you help me fix this please and tell me what I should have put in or did wrong? Thanks

### Restaurant Tipper Program
### Calculates total amount of bill including a 15% tip
print "Hello there!" \
	  " This program calculates total amount" \
	  " of bill you need to pay including a 15% tip" \
	  " So please enter your total bill amount and I will" \
	  " give you your total bill."
raw_bill= raw_input("Bill Total Amount: ")
float(raw_bill)
raw_bill= int(raw_bill)
raw_bill= 0.00+raw_bill
x=raw_bill
float(x)
tip_amt= x*.15
tip_amt=int(tip_amt)
print "Your tip for the inputted bill is", tip_amt, "dollars."
total_bill=raw_bill + tip_amt
total_bill= int(total_bill)
print "Your total bill, including the tip of", tip_amt, " dollars is", \
	  total_bill, \
	  "dollars."
raw_input("Press enter key to exit")


Is This A Good Question/Topic? 0
  • +

Replies To: Creating Tip Calculator Program

#2 xZachtmx  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 125
  • Joined: 14-June 09

Re: Creating Tip Calculator Program

Posted 14 June 2009 - 04:53 PM

well... it seems like you want the end result to be a full number like $45 instead of $44.8

so this chunk of code in the beginning
float(raw_bill)
raw_bill= int(raw_bill)
raw_bill= 0.00+raw_bill



is where your problem is happening.

The first line i posted up there is kinda useless...
and if you want it to be a float... then why in the second line do you make it into an integer?
and the third line dosent make much sense either..

I just did this... the end result is an integer... but you can fix that preety easily. The reason it wasnt working is because of the three lines above...
but here is something that works. if you need anymore help just ask. This is a preety easy script to tinker with:


### Restaurant Tipper Program
### Calculates total amount of bill including a 15% tip
print "Hello there!" \
	  " This program calculates total amount" \
	  " of bill you need to pay including a 15% tip" \
	  " So please enter your total bill amount and I will" \
	  " give you your total bill."
raw_bill= raw_input("Bill Total Amount: ")
x = float(raw_bill)
tip_amt= x*.15
tip_amt=int(tip_amt)
print "Your tip for the inputted bill is", tip_amt, "dollars."
total_bill= x + tip_amt
total_bill= int(total_bill)
print "Your total bill, including the tip of", tip_amt, " dollars is", \
	  total_bill, \
	  "dollars."
raw_input("Press enter key to exit")



i hope i helped you a bit.

This post has been edited by xZachtmx: 14 June 2009 - 04:54 PM

Was This Post Helpful? 1
  • +
  • -

#3 brianmen  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 39
  • Joined: 14-June 09

Re: Creating Tip Calculator Program

Posted 14 June 2009 - 06:56 PM

Hey, thanks a bunch for your help. Those three junk lines you pointed out were my attempt to get a decimal number to come out. What I want the program to do is take a value, say $19.78, multiply it by .15, then add those two values together (19.78+2.967) to get a grand total of 22.74. The program we were left with "works", but it rounds the tip down to $2.00 as opposed to the correct value of $2.78. Is there a way for me to get that fixed? Once again, thank you for your help!!!
Was This Post Helpful? 0
  • +
  • -

#4 atik97  Icon User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: Creating Tip Calculator Program

Posted 15 June 2009 - 01:58 AM

You need to use float instead of int. Take a look at the revised code-
### Restaurant Tipper Program
### Calculates total amount of bill including a 15% tip
print '''Hello there!
		 This program calculates total amount
		 of bill you need to pay including a 15% tip
		 So please enter your total bill amount and I will
		 give you your total bill.\n'''
raw_bill= raw_input("Bill Total Amount: ")
x = float(raw_bill)
tip_amt= x*.15
tip_amt=float(tip_amt)
print "Your tip for the inputted bill is", tip_amt, "dollars."
total_bill= x + tip_amt
total_bill= float(total_bill)
print "Your total bill, including the tip of", tip_amt, " dollars is", \
	  total_bill, \
	  "dollars."
raw_input("Press enter key to exit")


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1