Question

In: Computer Science

Given a total due and an array representing the amount of change in your pocket, determine...

Given a total due and an array representing the amount of change in your pocket, determine whether or not you are able to pay for the item. Change will always be represented in the following order: quarters, dimes, nickels, pennies.

To illustrate: changeEnough([25, 20, 5, 0], 4.25) should yield true, since having 25 quarters, 20 dimes, 5 nickels and 0 pennies gives you 6.25 + 2 + .25 + 0 = 8.50.

Examples
changeEnough([2, 100, 0, 0], 14.11) ➞ false

changeEnough([0, 0, 20, 5], 0.75) ➞ true

changeEnough([30, 40, 20, 5], 12.55) ➞ true

changeEnough([10, 0, 0, 50], 3.85) ➞ false

changeEnough([1, 0, 5, 219], 19.99) ➞ false
Notes
quarter: 25 cents / $0.25
dime: 10 cents / $0.10
nickel: 5 cents / $0.05
penny: 1 cent / $0.01

C++ language ?

Solutions

Expert Solution

The solution of the above problem is below:

The screenshot of code is:

The output screen is:

code--

  


#include <bits/stdc++.h>
using namespace std;

void changeEnough(int a[],double due)
{
double total=0.0;
for(int i=0;i<4;i++)
{
if(i==0)
{
total+=a[i]*(0.25);
}
if(i==1)
{
total+=a[i]*(0.10);
}
if(i==2)
{
total+=a[i]*(0.05);
}
if(i==3)
{
total+=a[i]*(0.01);
}
  
}
if(total>=due)
{
cout<<"true";
}
else
cout<<"false";
}

int main()
{
int arr[4],i;
for(i=0;i<4;i++)
{
cin>>arr[i];
}
double due;
cin>>due;
changeEnough(arr,due);
}
Please upvote in case of any query comment.


Related Solutions

Determine Due Date and Interest on Notes Determine the due date and the amount of interest...
Determine Due Date and Interest on Notes Determine the due date and the amount of interest due at maturity on the following notes: Date of Note Face Amount Interest Rate Term of Note a. January 10* $40,000 5% 90 days b. March 19 18,000 8 180 days c. June 5 90,000 7 30 days d. September 8 36,000 3 90 days e. November 20 27,000 4 60 days *Assume that February has 28 days. Assume 360-days in a year when...
Determine the due date and the amount of interest due at maturity on the following notes....
Determine the due date and the amount of interest due at maturity on the following notes. When calculating interest amounts, assume there are 350 days in a year. Note Issue Date Amount Interest Rate Time(Days) 1.   Jan. 20 $100,000 6% 30 2. March 10 $50,000 3% 60 3. May 15 $85,000 4% 45 4. Sept. 21 $90,000 7% 90    5. Dec.1    $75,000   8% 120 Note Due Date Interest on Note Maturity Value Select an answer: a. Feb. 19,...
Determine the due date and the amount of interest due at maturity on the following notes....
Determine the due date and the amount of interest due at maturity on the following notes. Assume 360 days per year. Date of Note Face Amount Interest Rate Term of Note (a) October 1 $21,000 8% 60 days (b) August 30 9,000 10 120 days (c) May 30 12,000 12 90 days (d) March 6 15,000 9 60 days (e) May 23 9,000 10 60 days Due Date Interest 1. $ 2. 3. 4. 5.
//   Given an array of size 9, with the values of 1-9, determine if the array...
//   Given an array of size 9, with the values of 1-9, determine if the array //   is valid or not. //   Display a message stating the row is VALId, or state its INVALID and what //   was the index number that determined the data invalid. // //   Use this java code as a start of your code. //   Test the array data by changing the values. //============================================================================= import java.util.*;    public class Soduko_ValidateRow    { public static void main(String...
Given an array ? of ? integers. Divide ? into three subsets such that the total...
Given an array ? of ? integers. Divide ? into three subsets such that the total absolute difference of subset sums between them is minimum. Provide python source code, time complexity, and pseudocode. thank you
Write a program with total change amount as an integer input, and output the change using...
Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. Ex: If the input is: 0 (or less than 0), the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes c++ please
For Java 3.25 LAB: Exact change Write a program with total change amount in pennies as...
For Java 3.25 LAB: Exact change Write a program with total change amount in pennies as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. Ex: If the input is: 0 the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes...
C++ 19.32 LAB: Exact change - functions Write a program with total change amount as an...
C++ 19.32 LAB: Exact change - functions Write a program with total change amount as an integer input that outputs the change using the fewest coins, one coin type per line. The coin types are dollars, quarters, dimes, nickels, and pennies. Use singular and plural coin names as appropriate, like 1 penny vs. 2 pennies. Ex: If the input is: 0 or less, the output is: no change Ex: If the input is: 45 the output is: 1 quarter 2...
6.32 LAB: Exact change - functions Write a program with total change amount as an integer...
6.32 LAB: Exact change - functions Write a program with total change amount as an integer input that outputs the change using the fewest coins, one coin type per line. The coin types are dollars, quarters, dimes, nickels, and pennies. Use singular and plural coin names as appropriate, like 1 penny vs. 2 pennies. Ex: If the input is: 0 or less, the output is: no change Ex: If the input is: 45 the output is: 1 quarter 2 dimes...
Determine the total cash inflows, the total cash outflows, and the expected change in cash for...
Determine the total cash inflows, the total cash outflows, and the expected change in cash for each month from January to July, 2019. Show your work in excel using excel functions. Based the findings, explain in your own words whether the company should borrow/invest and how much and in which months. The management estimates total sales for the period January, 2019 through June 2019 based on actual sales from the immediate past six months. The following assumptions are made: The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT