I'm trying to get the the dollar to say $D.CC. On my code when you put 8 quarters, 2 dimes, 0 nickels, 0 pennies you get get $2.2 but I want it to say $2.20. It is for a school assignment this is the lab
Ask the user what change they have in their pocket, and then tell them the total number of cents they have. Develop your algorithm first, and then write your code. Both are to be turned in.
This lab brings together the concepts of input and output in the practice of a calculator. Once you are able to tell the user the amount in cents that they have, also tell them how much that is in dollars. For this you will need to use “real” numbers, and remember that our currency is expressed in this fashion:
$D.CC
Where there may be multiple columns for dollars but there are always two for cents. The C++ Book (link in Classroom Basics) will have refresher examples of formatting output.
#include <iostream>
using namespace std;
int main()
{
//make variables
int quarters, dimes, nickels, pennies;
//gather data from user
cout << "We're going to find out how much money you have in change.\n";
cout << "how many qurters do you have?\n";
cin >> quarters;
cout << "How many dimes do you have?\n";
cin >> dimes;
cout << "How many nickels do you have?\n";
cin >> nickels;
cout << "How many pennies do you have?\n";
cin >> pennies;
// Example program
#include <iostream>
#include <string>
#include <iomanip>
usingnamespace std;
int main()
{
{
double f = 10.0;
cout.precision(2);
cout << fixed;
cout << setfill('0');
cout << f << endl;
}
{
double f = 2.2;
cout.precision(2);
cout << fixed;
cout << setfill('0');
cout << f << endl;
}
}
10.00
2.20
In a real-life program, you would avoid any floating-point calculations with money in the first place, and just put a decimal point between the third-to-last and second-to-last digit.