473,320 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

I'm having trouble with getting the correct tip

I'm having trouble with getting the correct tip:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. class Tips {
  8.   private:
  9.   double taxRate;
  10.  
  11.   public:
  12.   Tips();
  13.   Tips(double tRate);
  14.  
  15.   double computeTip(double totalBill, double tipRate);
  16.  
  17. };
  18.  
  19. Tips::Tips()
  20. {
  21.   taxRate = 0.065;
  22. }
  23. Tips::Tips(double tRate)
  24. {
  25.   taxRate = tRate;
  26. }
  27. double Tips::computeTip(double totalBill, double tipRate)
  28. {
  29.   return (totalBill + (totalBill * taxRate));
  30. }
  31.  
  32. int main()
  33. {
  34.   int    choice;
  35.   double charge,
  36.   bonus,
  37.   saleTx;
  38.  
  39.   bool running = true;
  40.  
  41.   while (running)
  42.   {
  43.  
  44.     cout << "Please enter the amount before tax.";
  45.     cin >> charge;
  46.  
  47.     if (charge < 0)
  48.     { cout << "Invalid entry. Negative numbers are not accepted.";
  49.       cout << "Please enter only positive values";
  50.       cin >> charge;
  51.     }
  52.  
  53.     cout << "Please enter the sales tax charged to the bill";
  54.     cin >> saleTx;
  55.  
  56.     Tips tips(saleTx);
  57.  
  58.     cout << "Please enter the tip rate given";
  59.     cin >> bonus;
  60.  
  61.     if (bonus < 0)
  62.     { cout << "Invalid entry. Negative numbers are not accepted.";
  63.       cout << "Please enter only postive values";
  64.       cin >> bonus;
  65.     }
  66.  
  67.     cout << "Your tip is: " << tips.computeTip(charge, bonus) << endl;
  68.     return 0;
  69.   }
  70. }
Nov 11 '14 #1

✓ answered by donbock

computeTip() has two parameters: totalBill and tipRate. However, the body of the function makes no use of the tipRate argument. Thus, when you call computeTip(charge,bonus) near the bottom of your code, the bonus argument is not used.

5 1102
donbock
2,426 Expert 2GB
Method computeTip() makes no use of the tipRate argument.
Nov 11 '14 #2
what are you saying?
Nov 11 '14 #3
donbock
2,426 Expert 2GB
computeTip() has two parameters: totalBill and tipRate. However, the body of the function makes no use of the tipRate argument. Thus, when you call computeTip(charge,bonus) near the bottom of your code, the bonus argument is not used.
Nov 11 '14 #4
Thanks for the help

ok I added the tiprate
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.   int    choice;
  4.   double charge,
  5.   tiprate,
  6.   bonus,
  7.   saleTx;
  8.  
  9.   bool running = true;
but the math isn't working still. How do I fix that?
Nov 11 '14 #5
Frinavale
9,735 Expert Mod 8TB
Dan5348,

Your math isn't working because, like donbock stated, your computeTip method needs to be modified to properly do the math.

Currently the method does this:
Expand|Select|Wrap|Line Numbers
  1.  double Tips::computeTip(double totalBill, double tipRate)
  2. {
  3.   return (totalBill + (totalBill * taxRate));
  4. }
Now in your main method you are retrieve information for the charge,saleTx, and bonus.

But your computeTip method only expects the total bill and tip rate to be provided to it.

Based on what you are retrieving from your user, you should be calling the computeTip method like this:
Expand|Select|Wrap|Line Numbers
  1.  tips.computeTip(charge, saleTx);
  2.  
But you are calling the method like this:
Expand|Select|Wrap|Line Numbers
  1.  tips.computeTip(charge, bonus) 
  2.  
Now, what doesn't make sense to us is the fact that you have this bonus but the computeTip method doesn't use it in calculating anything...

So, we recommend that you change your computeTip to take the bonus because it is obvious that it is used in your "math" somehow.

Your compute method should be something like:
Expand|Select|Wrap|Line Numbers
  1.  double Tips::computeTip(double totalBill, double tipRate, double bonus)
  2. {
  3.   //You now need to modify your math to 
  4.   //match the business rules that dictate 
  5.   //how to "compute the tip"
  6.  
  7.   //Obviously what you had before:
  8.   //   return (totalBill + (totalBill * taxRate));
  9.   //Is not correct because "bonus" isn't used
  10.   //Figure out what is required to compute the tip 
  11.   //taking "bonus" into consideration
  12.   //and change your math accordingly
  13.  
  14. }
PS:

In your main method you have while (running) but the variable running is never set to false and instead of allowing the while loop to actually loop you have a return 0; which ends app because this is main method (thankfully or else you would have an infinite loop)
Nov 12 '14 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Mason Hoke | last post by:
I am using SQLXML3 to return me XML formatted result. All the attributes are double quoted. When I try to response.write it as an XML data island to the client side like nothing comes over to the...
1
by: tperri | last post by:
Hi everyone, I have an .aspx file that is used by an external program to perform a function. There is no code behind, all code and HTML is contained in one file. the structure is like this: ...
3
by: BTInternet | last post by:
-- OHM ( Terry Burns ) . . . One-Handed-Man . . . If U Need My Email ,Ask Me Time flies when you don't know what you're doing
0
by: Google Mike | last post by:
I had RH9 Linux. It came with pgSQL, but I couldn't seem to figure out how to get PL/pgSQL going. I read the HTML documentation that came with it and was confused until I tried a few different...
0
by: Jake Barnes | last post by:
I've written a PHP script that makes an RSS feed for some mp3s so that the music studio I work for can offer some of its new music as a podcast. Often, after a podcast episode has gone live, and...
2
by: Jake Barnes | last post by:
I've read over the documentation for these effects: http://wiki.script.aculo.us/scriptaculous/show/CombinationEffectsDemo I want to include them on my page. I tried attaching using onload, but...
4
by: cmay | last post by:
I am beginning to wonder if it is not possible to get this working. I am trying to do: <root> <a/> <b/> <c/> </root>
4
SamKL
by: SamKL | last post by:
Firefox was my initial testing browser for this design, and it looks just fine in FF... Opera, and IE both disagree however... the main part of the design looks fine, really. The hex-cells line up...
1
by: egrill | last post by:
I am linking the tables in Access through my SQL server. It is accounting programming that uses status determine the type of document; 8 for sales order and 11 for credit orders. 11 are negative...
1
by: ced69 | last post by:
having trouble getting marquee to work get object required errors tring t <title>This Month at the Chamberlain Civic Center</title> <link href="styles.css" rel="stylesheet"...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.