How many different final sums satisfy the conditions

Assignment Help Computer Engineering
Reference no: EM132105172

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;
}

Reference no: EM132105172

Questions Cloud

Broken up into three sub-accounts : Since the inventory costs of a manufacturing firm are broken up into three sub-accounts
Benefits and challenges of virtual teams : What are the potential benefits and challenges of virtual teams and it will impact a project?
Managed for a team composed of members : How can Virtual Teams be managed for a team composed of members who are all co-located in project management?
Discuss the differences between the terms product scope : Discuss the differences between the terms "product scope" and "project scope" and explain how scope
How many different final sums satisfy the conditions : Write a function that computes how many different final sums satisfy the conditions .
Monitor the health of the project : What are some key components to monitor the health of the project, as it relates to earned value?
Wbs for an it project : Newly appointed project manager in my company asked me to review his WBS for an IT project. The thirty-day project had 340 work packages
Demonstrate application of business strategy : Demonstrate application of Business Strategy - External analysis - You may incorporate strategical tools from the buttom - Write a report on one nominated case
What are five problems within the case study : What are five problems within the case study? Does the creation of a MIS group solve any problems? Why or why not?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd