Your program will read eight numbers from the user. These eight inputs correspon
ID: 3673055 • Letter: Y
Question
Your program will read eight numbers from the user. These eight inputs correspond to the number of $20 bills, $10 bills, $5 bills, $1 bills, quarters, dimes, nickels and pennies that you have. Each of these inputs is an integer value. The user will always enter them in this order ($20–$10–$5–$1–quarter–dime–nickel–penny) and will always give legal input values (all the inputs will be zero or a positive integer). To complete this project, you need to know a couple of basic facts about pennies. First, we assume all the pennies are new (copper plated zinc) pennies. These pennies Have a weight of 2.500 grams Have a diameter of 0.750 inches Have a thickness of 1.52mm (recall that there are 25.4 mm in one inch) This information above was taken from https://www.usmint.gov/about_the_mint/?action=coin_specifications For this project, you need to use functions. We will introduce functions on Wednesday. At a minimum, you need: A function to get input from the user. This function takes one argument (a character string that is the prompt for the user when entering input), prints the prompt, reads a single integer from standard input, and returns the integer value that was entered. A function that takes an integer representing the total number of pennies that you have and computes the weight of those pennies in pounds. It returns a double that represents this weight. A function that takes an integer representing the total number of pennies that you have and computes the volume of these pennies in cubic feet. It returns a double that represents this volume. What You Need To Do Create a directory called project1 on your machine. In that directory, create a file named pennies.c In pennies.c, write the code needed to solve the problem stated above. Make sure that your program o Has a header block of comments that includes your name and a brief overview of the program o Reads eight values from the user (twenties, tens, fives, ones, quarters, dimes, nickels, pennies) o Use at least three functions – one for input, one to calculate weight, one to calculate volume o Prints the three expected outputs The equivalent total number of pennies for this amount of money The total weight of these pennies (in pounds) The total volume of these pennies (in cubic feet)
Explanation / Answer
Some compilers (eg. Bloodshed’s Dev C++) don’t automatically pause the console screen after the program has finished executing. If this is the case with your compiler, the following two steps will fix your problem:
First, add the following line near the top of your program:
1
#include <iostream>
Second, add the following code at the end of the main() function (right before the return statement):
1
2
3
std::cin.clear(); // reset any error flags
std::cin.ignore(32767, ' '); // ignore any characters in the input buffer until we find an enter character
std::cin.get(); // get one more char from the user
This will cause your program to wait for you to press a key before continuing, which will give you time to examine your program’s output before your compiler closes the console window.
Other solutions, such as the commonly suggested system("pause") solution may only work on certain operating systems and should be avoided.
Note: Visual Studio will not pause at the end of a console application if it is run with debugging (Debug Menu->Start Debugging). If you want it to pause, you can either use the code solution above, or run your program without debugging (Debug Menu->Start Without Debugging).
1
#include <iostream>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.