Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
Question
Book Icon
Chapter 14, Problem 7PP
Program Plan Intro

Chocolate Bars and Coupons

Program plan:

  • Include required header file.
  • Declare the function for compute chocolate bars
  • Define main function.
    • Declare variable for “nDollars” and “result”.
    • Create prompt statement for ask the number of dollars.
    • Read the number of dollars from the user.
    • Call the function “calculateChocolateBars” with “nDollars” and “coupons” and then store the result in a variable “result”.
    • Finally display the result.
  • Define “calculateChocolateBars” function with argument “nDollars” and “coupons”.
    • If the value of “nDollars” is equal to “0” and the value of “coupons” is less than “7”, then returns nothing.
    • Otherwise, first assigns the value of dollars to a variable “res”. Then compute the value of coupons.
    • Finally returns the number of chocolate bars by recursively call the function “calculateChocolateBars” with dividing and moduling the coupons with “7” and then add with “res”.

Blurred answer
Students have asked these similar questions
How do you distinguish between hardware and a software problem? Discuss theprocedure for troubleshooting any hardware or software problem. give one reference with your answer.
You are asked to explain what a computer virus is and if it can affect computer’shardware or software. How do you protect your computer against virus? give one reference with your answer.
Distributed Systems: Consistency Models fer to page 45 for problems on data consistency. structions: Compare different consistency models (e.g., strong, eventual, causal) for distributed databases. Evaluate the trade-offs between availability and consistency in a given use case. Propose the most appropriate model for the scenario and explain your reasoning. Link: [https://drive.google.com/file/d/1wKSrun-GlxirS31Z9qoHazb9tC440AZF/view?usp=sharing]
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole