Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function that takes inputs of a number of quarters, dimes, and nickels (

ID: 3541152 • Letter: W

Question

Write a function that takes inputs of a number of quarters, dimes, and nickels (whole numbers), then calculates and returns an output of the value of the total amount of money in dollars (a floating-point value).  Use appropriate parameter passing and return mechanisms. Use appropriate datatypes.  For example, with inputs of 4 quarters, 3 dimes, and 3 nickels, the result would be 1.45 dollars. Use proper code formatting techniques. Do not write a main routine. Your function does not do cin or cout.

Explanation / Answer

#include<iostream>
#include<iomanip>
using namespace std;

float dollars(int quarters,int dimes,int nickels)
{
return (float)(quarters)/4.0 + (float)(dimes)*0.1 + (float)nickels*0.05;
}
int main()
{
cout << dollars(4,3,3) << setprecision(3)<<endl;
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote