In: Computer Science
Write a program in c++ that prompts the user to input a coin collection of number of quarters, dimes, nickels
and pennies. The program should then convert the coin collection into currency value as dollars. The
coin values should all be whole numbers and the resulting currency value should be displayed with two
decimals. An example of user interaction is as follows:
Coin Convertor
Enter number of quarters:
3
Enter number of dimes:
1
Enter number of nickels:
4
Enter number of pennies:
12
3 quarters(s), 1 dime(s), 4 nickel(s), and 12 penny(ies) is equal to $1.17
First analyze the problem and write the spec in the order of NARRATIVE, INPUT, OUTPUT, CONSTANTS,
CONSTRAINTS, and OPERATIONS, and then code the program according to the spec. Place the spec at
the top of cpp file as comments. The run-time interaction should be formatted exactly as illustrated
above. The constant values 100, 25, 10, and 5 should each be named constant of integer type.
Grading Scale:
Spec is correct and agrees with code
4
Use meaningful variable names
1
Use named constants
2
Code is properly formatted
1
Program compiles and runs correctly
5
Output is formatted properly (or as required) with two decimal
places
2
Total
15
please help.
#include <iostream> #include <iomanip> using namespace std; int main() { // declare constant variables const float dollars = 100.0; const int quarters = 25; const int dimes = 10; const int nickels = 5; int q, d, n, p; // read values for each unit cout << "Coin Convertor" << endl; cout << "Enter number of quarters:" << endl; cin >> q; cout << "Enter number of dimes:" << endl; cin >> d; cout << "Enter number of nickels:" << endl; cin >> n; cout << "Enter number of pennies:" << endl; cin >> p; // calculate the total amount in dollars float total = (q * quarters + d * dimes + n * nickels + p) / dollars; // display the result in required format cout << "\n" << q << " quarter(s), " << d << " dime(s), " << n << " nickel(s), and " << p << " penny(ies) is equal to $" << setprecision(3) << total; }
FOR HELP AND MODIFICATION PLEASE COMMENT.
THANK YOU