/**************************************************
// Function: calculateJarValue
//
// Description: Calculates the total monetary value of a jar containing
// various coins (dollars, half-dollars, quarters, dimes,
// nickels, and pennies).
//
// Parameters: dollars - number of dollar coins
// halfDollars - number of half-dollar coins
// quarters - number of quarter coins
// dimes - number of dime coins
// nickels - number of nickel coins
// pennies - number of penny coins
//
// Returns: totalValue - total monetary value in dollars (float)
// ***************************************************/
#include <stdio.h>
float calculateJarValue(int dollars, int halfDollars, int quarters, int dimes, int nickels, int pennies) {
// Coin values in dollars
const float VALUE_DOLLAR = 1.00;
const float VALUE_HALF_DOLLAR = 0.50;
const float VALUE_QUARTER = 0.25;
const float VALUE_DIME = 0.10;
const float VALUE_NICKEL = 0.05;
const float VALUE_PENNY = 0.01;
// Calculate total value
float totalValue = (dollars * VALUE_DOLLAR) +
(halfDollars * VALUE_HALF_DOLLAR) +
(quarters * VALUE_QUARTER) +
(dimes * VALUE_DIME) +
(nickels * VALUE_NICKEL) +
(pennies * VALUE_PENNY);
return totalValue;
}
int main() {
// Test the calculateJarValue function with given values
int dollars = 0;
int halfDollars = 11;
int quarters = 7;
int dimes = 3;
int nickels = 12;
int pennies = 17;
float totalValue = calculateJarValue(dollars, halfDollars, quarters, dimes, nickels, pennies);
// Print the result
printf("The total value in the jar is: $%.2f\n", totalValue);
return 0;
}
LyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCi8vIEZ1bmN0aW9uOiBjYWxjdWxhdGVKYXJWYWx1ZQovLwovLyBEZXNjcmlwdGlvbjogQ2FsY3VsYXRlcyB0aGUgdG90YWwgbW9uZXRhcnkgdmFsdWUgb2YgYSBqYXIgY29udGFpbmluZwovLyAgICAgICAgICAgICAgdmFyaW91cyBjb2lucyAoZG9sbGFycywgaGFsZi1kb2xsYXJzLCBxdWFydGVycywgZGltZXMsCi8vICAgICAgICAgICAgICBuaWNrZWxzLCBhbmQgcGVubmllcykuCi8vCi8vIFBhcmFtZXRlcnM6IGRvbGxhcnMgICAg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VlCiAgICBmbG9hdCB0b3RhbFZhbHVlID0gKGRvbGxhcnMgKiBWQUxVRV9ET0xMQVIpICsKICAgICAgICAgICAgICAgICAgICAgICAoaGFsZkRvbGxhcnMgKiBWQUxVRV9IQUxGX0RPTExBUikgKwogICAgICAgICAgICAgICAgICAgICAgIChxdWFydGVycyAqIFZBTFVFX1FVQVJURVIpICsKICAgICAgICAgICAgICAgICAgICAgICAoZGltZXMgKiBWQUxVRV9ESU1FKSArCiAgICAgICAgICAgICAgICAgICAgICAgKG5pY2tlbHMgKiBWQUxVRV9OSUNLRUwpICsKICAgICAgICAgICAgICAgICAgICAgICAocGVubmllcyAqIFZBTFVFX1BFTk5ZKTsKCiAgICByZXR1cm4gdG90YWxWYWx1ZTsKfQoKaW50IG1haW4oKSB7CiAgICAvLyBUZXN0IHRoZSBjYWxjdWxhdGVKYXJWYWx1ZSBmdW5jdGlvbiB3aXRoIGdpdmVuIHZhbHVlcwogICAgaW50IGRvbGxhcnMgPSAwOwogICAgaW50IGhhbGZEb2xsYXJzID0gMTE7CiAgICBpbnQgcXVhcnRlcnMgPSA3OwogICAgaW50IGRpbWVzID0gMzsKICAgIGludCBuaWNrZWxzID0gMTI7CiAgICBpbnQgcGVubmllcyA9IDE3OwoKICAgIGZsb2F0IHRvdGFsVmFsdWUgPSBjYWxjdWxhdGVKYXJWYWx1ZShkb2xsYXJzLCBoYWxmRG9sbGFycywgcXVhcnRlcnMsIGRpbWVzLCBuaWNrZWxzLCBwZW5uaWVzKTsKCiAgICAvLyBQcmludCB0aGUgcmVzdWx0CiAgICBwcmludGYoIlRoZSB0b3RhbCB2YWx1ZSBpbiB0aGUgamFyIGlzOiAkJS4yZlxuIiwgdG90YWxWYWx1ZSk7CgogICAgcmV0dXJuIDA7Cn0K
MCBkb2xsYXJzLCAKMTEgaGFsZi1kb2xsYXJzLAogNyBxdWFydGVycywgCjMgZGltZXMsIDEKMiBuaWNrZWxzLAoxNyBwZW5uaWVz
0 dollars,
11 half-dollars,
7 quarters,
3 dimes, 1
2 nickels,
17 pennies