write a PHP program makes change for a given number of cents. The program should ask the user for the amount of cents and then output the change for specific denominations of ten dollar bills, five dollar bills, one dollar bills, quarters, dimes, nickels, and pennies.
Here is a sample program output for an input of 265 cents:
Change for 2 dollars and 65 cents :
0 ten dollar bills
0 five dollar bills
2 one dollar bills
2 quarters
1 dime
1 nicke
l 0 pennies
The PHP function readline can be used to get user input. The function can be used as follows: // prompt the user and store the result in the variable $input $input = readline (" Prompt ")
Explanation in the code is written in comments wherever needed.
Code:
<?php
$input = readline ("Enter amount in cents");
//$rem variable is used to calculate
$rem = $input;
//variables to store number of denominations
$dollarTen = 0; // Ten dollar is 1000 cents
$dollarFive = 0; // Five dollar is 500 cents
$dollarOne = 0; // One dollar is 100 cents
$quarters = 0; // One quarter is 25 cents
$dimes = 0; // One dime is 10 cents
$nickels = 0; // One nickel is 5 cents
$pennies = 0; // One penny is one cent
//floor() function is used to round down the nearest integer
value
if (is_numeric($rem)) {
//to find the number of ten dollar
if ($rem >= 1000) {
$dollarTen = floor($rem / 1000); //using floor to get remove
decimal values
$rem = $rem - ($dollarTen * 1000);
}
//to find the number of five dollar
if ($rem >= 500) {
$dollarFive = floor($rem / 500); //using floor to get remove
decimal values
$rem = $rem - ($dollarFive * 500);
}
//to find the number of one dollar
if ($rem >= 100) {
$dollarOne = floor($rem / 100); //using floor to get remove decimal
values
$rem = $rem - ($dollarOne * 100);
}
//to find the number of quarters
if ($rem >= 25) {
$quarters = floor($rem / 25); //using floor to get remove decimal
values
$rem = $rem - ($quarters * 25);
}
//to find the number of dimes
if ($rem >= 10) {
$dimes = floor($rem / 10); //using floor to get remove decimal
values
$rem = $rem - ($dimes * 10);
}
//to find the number of nickels
if ($rem >= 5) {
$nickels = floor($rem / 5); //using floor to get remove decimal
values
$rem = $rem - ($nickels * 5);
}
//remaining will be the number of the pennies
$pennies = $rem;
}
//calculating the values for the first line of output
$cents = $input % 100; //using modulus operator to find the number
of cents
$dollr = ($input - $cents) / 100; //to find the number of
dollars
//i have used '\n' for new line, '\r\n' or nl2br() can also be
used
echo "\nChange for ".$dollr." dollars and ".$cents." cents
:\n";
echo $dollarTen." ten dollar bills\n";
echo $dollarFive." five dollar bills\n";
echo $dollarOne." one dollar bills\n";
echo $quarters." quarters\n";
echo $dimes." dime\n";
echo $nickels." nickel\n";
echo $pennies." pennies";
write a PHP program makes change for a given number of cents. The program should ask...
C Program that prompts the user to enter a number that represents a pile of pennies. Then, the program should use that input value to distribute the cents over monetary denominations of dollars, half dollars, quarters, dimes, nickels and pennies. Distribute the pennies over the other denominations with Change function : prototype: void Change(int *dollars, int *halfDollars, int *quarters, int *dimes, int *nickels, int *pennies); The function takes a logical input value via its pennies parameter that represents the total...
(In Python 3) 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 So...
All items at a "Penny Fair" are priced less than $1.00. Write a program that makes change with a minimum number of coins when a customer pays for an item with a one dollar bill. Prompt for the item price in cents, report the change due, and the number of coins of each denomination required. Use only quarters, dimes, nickels, and pennies for change (no 50 cent pieces). See sample output but your program should work for any item price....
*Create in Python 3: Change Calculator Create a program that calculates the coins needed to make change for the specified number of cents. Sample Console Output Change Calculator Enter number of cents (0-99): 99 Quarters: 3 Dimes: 2 Nickels: 0 Pennies: 4 Continue? (y/n): y Enter number of cents (0-99): 55 Quarters: 2 Dimes: 0 Nickels: 1 Pennies: 0 Continue? (y/n): n Bye! Specifications The program should display the minimum number of quarters, dimes, nickels, and pennies that one needs...
Write a program called "ConvertPennies" to input an integer value representing a number of pennies and convert it to its equivalent number of Dollars, Quarters, Dimes, Nickels and Pennies. Following is the result of the execution of this program for 292 pennies. Enter the amount of pennies to convert: 292 pennies is equal to 2 one dollar bills 3 quarters 1 dimes 1 nickels 2 pennies Have a nice day! This is given: //********************************************************************** // Programmer: Your first and last...
C++
Write a program that helps a young student learn to make change.
Use the random number generator to generate change amounts
between1¢ and 99¢. Ask the user how many quarters, dimes, nickels
and pennies they need to make that amount. Determine whether the
coins specified by the user total the specified amount and give
them feedback on their answer including whether they used the
minimum or optimum number of coins to produce the amount.
Sample output of a program...
Write a C program that calculates exact change. In order to receive full credit, please remember that only int arithmetic is exact, so you’ll need to break up your double into two ints, the one before the decimal point and the one after the decimal point. Another point worth mentioning is that the % operator gives the remainder. In other words, when working with int values, 9 / 5 = 1 whereas 9 % 5 = 4. Keep this in...
C++ HW Question Your program will simulate a simple change maker for a vending machine. It will start with a stock of coins and dollars. It will then repeatedly request the price for an item to be purchased or to quit. If given a price, it will accept nickels, dimes, quarters, one-dollar and five-dollar bills—deposited one at a time—in payment. When the user has deposited enough to cover the cost of the item, the program will calculate the coins to...
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 the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes
Describe how you would create a Python program that calculates the exact amount of change to give a customer in denominations of quarters, dimes, nickels, and pennies. For example, if the change is 79 cents, how many of each coin would be needed to give change?