Question

In: Computer Science

Write a program in c++ that prompts the user to input a coin collection of number...

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.

Solutions

Expert Solution

#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


Related Solutions

IN C++ Write a program that prompts the user to enter the number of students and...
IN C++ Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score (display the student’s name and score). Also calculate the average score and indicate by how much the highest score differs from the average. Use a while loop. Sample Output Please enter the number of students: 4 Enter the student name: Ben Simmons Enter the score: 70 Enter the student name:...
Write a complete C++ program that prompts the user for and takes as input, numbers until...
Write a complete C++ program that prompts the user for and takes as input, numbers until the user types in a negative number. the program should add all of the numbers together. Then if the result is less than 20 the program should multiply the result by 3, otherwise subtract 2 from the result. Finally, the program should printout the result.
Write a C++ program that prompts the user (or “Player 1”) to input an integer value...
Write a C++ program that prompts the user (or “Player 1”) to input an integer value between 1 and 3 (where 1=paper, 2=scissor, and 3=rock). This input should be passed into a string function called player_RPS(), and returns a string value indicating the selection of paper, scissors, or rock (as mentioned above). Next, the returned string value, along with a generated input from the computer, should be passed into a void function called RPS_comparison(), and determines whether the user’s input...
write this program in C++ Write a program that prompts a user for three characters. The...
write this program in C++ Write a program that prompts a user for three characters. The program must make sure that the input is a number 10 - 100 inclusive. The program must re prompt the user until a correct input is entered. Finally output the largest and the lowest value. Example 1: Input : 10 Input : 20 Input : 30 The largest is 30. The lowest is 10. Example 2: Input : 100 Input : 50 Input :...
Write a C++ program that prompts the user for the radius of a circle and then...
Write a C++ program that prompts the user for the radius of a circle and then calls inline function circleArea to calculate the area of that circle. It should do it repeatedly until the user enters -1. Use the constant value 3.14159 for π Sample: Enter the radius of your circle (-1 to end): 1 Area of circle with radius 1 is 3.14159 Enter the radius of your circle (-1 to end): 2 Area of circle with radius 2 is...
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
C++ Question: write a program that prompts the user for the length and width of a...
C++ Question: write a program that prompts the user for the length and width of a rectangle in inches.  The program then uses functions to compute the perimeter and area of the rectangle and to convert those to meters and square meters respectively. Sample output from one instance of the program is shown below: ```html Welcome to the Foot-To-Meter Rectangle Calculator ================================================= Enter the rectangle length in feet: 2 Enter the rectangle width in feet: 3 The rectangle dimensions are: 0.61...
Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
Include<stdio.h> Write a program that prompts the user to input the elapsed time for an event...
Include<stdio.h> Write a program that prompts the user to input the elapsed time for an event in seconds. The program then outputs the elapsed time in hours, minutes, and seconds. For example: Enter the elapsed time in second: 9630 The elapsed time in seconds = 9630 The equivalent time in hours:minutes:seconds = 02:40:30
C++ Program: Write a program that prompts the user for two numbers and stores them in...
C++ Program: Write a program that prompts the user for two numbers and stores them in signed integers. The program should then add those two numbers together and store the result in a signed integer and display the result. Your program should then multiply them by each other and store the result in another integer and display the result. Then do the same but with dividing the first number by the second. Display an error message to the screen if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT