Suppose you can buy a chocolate bar from the vending machine for $1 each. Inside every chocolate bar is a coupon. You can redeem seven coupons for one chocolate bar from the machine. You would like to know how many chocolate bars you can eat, including those redeemed via coupon, if you have n dollars.
For example, if you have 20 dollars then you can initially buy 20 chocolate bars. This gives you 20 coupons. You can redeem 14 coupons for two additional chocolate bars. These two additional chocolate bars give you two more coupons, so you now have a total of eight coupons. This gives you enough to redeem for one final chocolate bar. As a result you now have 23 chocolate bars and two leftover coupons.
Write a
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Absolute C++
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects (9th Edition)
Modern Database Management
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out With Visual Basic (8th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Mechanics of Materials (10th Edition)
- Let's begin with a lesson in roulette. Roulette is a casino game that involves spinning a ball on a wheel that is marked with numbered squares that are red, black, or green. Half of the numbers 1–36 are colored red and half are black and the numbers 0 and 00 are green. Each number occurs only once on the wheel. We can make many different types of bets, but two of the most common are to bet on a single number (1–36) or to bet on a color (either red or black). These will be the two bets we will consider in this project. After all players place their bets on the table, the wheel is spun and the ball tossed onto the wheel. The pocket in which the ball lands on the wheel determines the winning number and color. The ball can land on only one color and number at a time. We begin by placing a bet on a number between 1 and 36. This bet pays 36 to 1 in most casinos, which means we will be paid $36 for each $1 we bet on the winning number. If we lose, we simply lose whatever amount of money we…arrow_forwardLet's begin with a lesson in roulette. Roulette is a casino game that involves spinning a ball on a wheel that is marked with numbered squares that are red, black, or green. Half of the numbers 1–36 are colored red and half are black and the numbers 0 and 00 are green. Each number occurs only once on the wheel. We can make many different types of bets, but two of the most common are to bet on a single number (1–36) or to bet on a color (either red or black). These will be the two bets we will consider in this project. After all players place their bets on the table, the wheel is spun and the ball tossed onto the wheel. The pocket in which the ball lands on the wheel determines the winning number and color. The ball can land on only one color and number at a time. We begin by placing a bet on a number between 1 and 36. This bet pays 36 to 1 in most casinos, which means we will be paid $36 for each $1 we bet on the winning number. If we lose, we simply lose whatever amount of money we…arrow_forwardSuppose you have a knapsack that can carry up to 17 pounds. You can only put certain items, and each item has a weight and a value. You want to put the items that will give you the highest possible value, but you can only carry up to 15 pounds. Here are the items you can put and their weights and values: I Weight value Value/Weight 1 2 10 5 2 4 30 7.5 3 6 50 8.33 4 9 70 7.78 5 10 80 8 Table 1: Caption Your task is to solve the Knapsack Problem using a greedy approach.Hints:- Sort the items by their value-to-weight ratio in descending order. Start with the item with the highest value-to-weight ratio and add it to the knapsack. - Continue adding items to the knapsack in descending order of their value-to-weight ratio until the knapsack is full or there are no more items left. - Your solution should output the total value of the items in the knapsack and the list of items that you have put. -This…arrow_forward
- TYPEWRITTEN ONLY PLEASE FOR UPVOTE. DOWNVOTE FOR HANDWRITTEN. DO NOT ANSWER IF YOU ALREADY ANSWERED THIS. I'LL DOWNVOTE.arrow_forwardSuppose you are a computer salesman and your income depend on the total sales and commissions earned for the computers that you sell. Commission rates vary depending on how many units you sold (see chart below). Your income equals to the total sales plus the commission where the commission equals to total sales times the commission rate. That is, commission = total sales * commission rate and income = total sales + commission. Total Sales Commission rate % Less than 200 sold 8% (totalsales < 200) Greater or equal to 200 sold 10% (totalsales >=200 & totalsales <400) Greater than to 400 sold 12% (if (totalsales >= 400) Use Multiway if, else if (use as many you need) and else correctly Review slides 3-CH-2 Slide 4 and 8 Write the code correctly as show in the chapter slides. Pay attention to the commission chart above: (3) input as examples shown 500, 250, 150 You can work with your team and submit your code and output in PDF. 1. Provide the user the commission rate list…arrow_forwardTYPEWRITTEN ONLY PLEASE UPVOTE. DOWNVOTE FOR HANDWRITTEN. DO NOT ANSWER IF YOU ALREADY ANSWERED THIS. THE BIG NUMBER IN THE SIDE IS FOR NUMBERING.arrow_forward
- Correct answer will be upvoted else downvoted. Computer science. You have w white dominoes (2×1 tiles, the two cells are hued in white) and b dark dominoes (2×1 tiles, the two cells are shaded in dark). You can put a white domino on the board in case both board's cells are white and not involved by some other domino. Similarly, you can put a dark domino if the two cells are dark and not involved by some other domino. Would you be able to put all w+b dominoes on the board if you can put dominoes both on a level plane and in an upward direction? Input The main line contains a solitary integer t (1≤t≤3000) — the number of experiments. The primary line of each experiment contains three integers n, k1 and k2 (1≤n≤1000; 0≤k1,k2≤n). The second line of each experiment contains two integers w and b (0≤w,b≤n). Output For each experiment, print YES in case it's feasible to put all w+b dominoes on the board and negative, in any case. You might print each letter…arrow_forwardAn arcade game player wants to climb to the top of the leaderboard and track their ranking. The game uses Dense Ranking, so its leaderboard works like this: The player with the highest score is ranked number on the leaderboard. Players who have equal scores receive the same ranking number, and the next player(s) receive the immediately following ranking number. Example The ranked players will have ranks , , , and , respectively. If the player's scores are , and , their rankings after each game are , and . Return . Function Description Complete the climbingLeaderboard function in the editor below. climbingLeaderboard has the following parameter(s): int ranked[n]: the leaderboard scores int player[m]: the player's scores Returns int[m]: the player's rank after each new score Input Format The first line contains an integer , the number of players on the leaderboard.The next line contains space-separated integers , the leaderboard scores in decreasing order.The next…arrow_forwardA large company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9% their gross sales for that week. For example, a salesperson who sells $5,000 worth of merchandise in a week receives $200 plus 9% of $5,000, or a total of $650. You’ve been supplied with a list of the items sold by each salesperson. The values of these items are shown in the table below. Develop a Java application that inputs one salesperson's items sold for last week and calculates and displays that salesperson's earnings. There is no limit to the number of items that can be sold. Item Value 239.99 2 129.75 3 99.95 4 350.89 Objectives This assignment was designed to reinforce programming concepts from Chapter 4. In this assignment you will practice: • Using if-else statements Sample Runs Run: Run: Enter number sold of product #1: 20 Enter number sold of product #2: 30 Enter number sold of product #3: 0 Enter number sold of product #4: 45 Earnings this week: $2403.41 Enter number…arrow_forward
- Fix the example such that the cost of frozen yogurt is O if you pour exactly 1 lb. in your cup. * 1 weight = 0.5 2 if weight 1: 3 price = 1.15 6 total = weight * price 7 print(weight) 8 print(price) 9 print(total) 10 Your answerarrow_forwardYou need to take a trip by car to another town that you have never visited before. Therefore, you are studying a map to determine the shortest route to your destination. Depending on which route you choose, there are five other towns (call them A, B, C, D, E) that you might pass through on the way. The map shows the mileage along each road that directly connects two towns without any intervening towns. These numbers are summarized in the following table, where a dash indicates that there is no road directly connecting these two towns without going through any other towns. Miles between Adjacent Towns Town A B C DE Destination Origin A 40 60 50 10 70 B 20 55 40 50 10 D 60 E 80 (a) Formulate this problem as a shortest-path problem by drawing a network where nodes represent towns, links represent roads, and numbers indicate the length of each link in miles. (b) Use the Dijkstra's algorithm to solve this shortest path problem.arrow_forwardYou need to take a trip by car to another town that you have never visited before. Therefore, you are studying a map to determine the shortest route to your destination. Depending on which route you choose, there are five other towns (call them A, B, C, D, E) that you might pass through on the way. The map shows the mileage along each road that directly connects two towns without any intervening towns. These numbers are summarized in the following table, where a dash indicates that there is no road directly connecting these two towns without going through any other towns. Town Origin A B C D E A 40 Miles between Adjacent Towns C D E B 60 10 50 20 - 70 55 - 88811 40 50 10 Destination | | || 88 60 80 (a) Formulate this problem as a shortest-path problem by drawing a network where nodes represent towns, links represent roads, and numbers indicate the length of each link in miles. (b) Use the Dijkstra's algorithm to solve this shortest path problem. Illustrate your work by using a table.…arrow_forward
- Operations Research : Applications and AlgorithmsComputer ScienceISBN:9780534380588Author:Wayne L. WinstonPublisher:Brooks Cole