Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Problem Statement

In a restaurant, if you were pleased by the waiter's service, you may leave him a tip -- you pay him more than the actual value of the bill, and the waiter keeps the excess money. In some countries, not leaving a tip for the waiter is even considered impolite. During my recent holiday I was having dinner in a foreign restaurant. The pamphlet from my travel agency informed me that the proper way of tipping the waiter is the following:

The sum I pay must be round, i.e., divisible by 5.

The tip must be between 5% and 10% of the final sum I pay, inclusive.

Clearly, sometimes there may be multiple "correct" ways of settling the bill. I'd like to know exactly how many choices I have in a given situation. I could program it easily, but I was having a holiday... and so it's you who has to solve this task. You will be given:

an int bill -- the amount I have to pay for the dinner

an int cash -- the amount of money I have in my pocket

Write a function that computes how many different final sums satisfy the conditions above.

Constraints

Assume that both bill and cash are in dollars.

All the money I have is in one-dollar banknotes.

My Code:

int possible_payments(int bill, int cash) {
// fill in code here
int choices;
int counter = 0;
int leftoverCash = cash - bill;
int i = 0;

for (i; i < leftoverCash; i++){
int tipPercent = (i/bill)*100;
int total = i + bill;
if((total % 5 == 0) && (tipPercent <= 10) && (tipPercent >= 5)){
counter++;
}
}

return choices;
}

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M93092641

Have any Question?


Related Questions in Computer Engineering

1nbsphillary wants to go to disneyland in 425 years she

1) Hillary wants to go to Disneyland in 4.25 years. She wants to take her partner and 2 kids (4 people in Total). If it is going to cost $453.27 per person to go on the trip. -What will the cost be for the entire trip? - ...

Question in sql database hospital systems suffer from 4-10

Question : In SQL Database, Hospital Systems suffer from 4-10% duplicate patients in the EHR. Some is that patients do not know the relationships of medical facilities in the same organization. What can you do to identif ...

Do you need computers or information and communication

Do you need computers or information and communication technologies to store, organize, and manage data in organizations? Explain how the present day organizations in a developed country like the USA store and manage the ...

Explain that our ability to secure each computers stored

Explain that our ability to secure each computers stored information is now influenced by the security on each computer to which it is connected

This is sports data analysis class please help me out with

This is sports data analysis class. please help me out with this assignment. Background Bill James created a career projection system he called his "favorite toy," presumably because he liked projecting the career totals ...

Question suppose that the head of a disk with 256 tracks

Question : Suppose that the head of a disk with 256 tracks, numbered 0 to 255, is currently serving a request at track 58. The previously served request was at a lower-numbered track (i.e., the head is currently moving f ...

Solve the following problem from fibonaccis liber abacia

Solve the following problem from Fibonacci's Liber abaci: A man left to his eldest son one bezant and a seventh of what was left; then from the remainder, to his next son he left two bezants and a seventh of what was lef ...

Design a automatic room climate control system with

Design a automatic room climate control system with contextual model, state transition diagram

Tasks1 identify possible actors and use cases involved in

Tasks: 1. Identify possible actors and use cases involved in Personal Trainer's operations. 2. Create an object relationship diagram for the Personal Trainer information system. 3. Create a use case diagram for the syste ...

Question need two different postsresponses with 200 words

Question: Need two different posts(responses) with 200 words each. After reviewing the assigned reading materials, complete the following activities: 1. Develop a product service idea. A. Describe the product/service inc ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As