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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.