i wnat this programe in c++ language Create a change-counting game that asks the
ID: 3678262 • Letter: I
Question
i wnat this programe in c++ language
Create a change-counting game that asks the user to enter what coins to use to make exactly one dollar. The program should ask the user to enter the number of pennies, nickels, dimes, and quarters. If the total value of the coins inserted is equal to one dollar the program should congratulate the user for winning the game. Otherwise, the program should display a message indicating whether the amount entered was more or less than one dollar. Use constant variables to hold the coin values.
Explanation / Answer
#include <iomanip>
#include <string>
#include <iostream>
#include <cmath>
using namespace std;
int main(){
const double VAL_PENNIES = .01,
VAL_NICKELS = .05,
VAL_DIMES = .1,
VAL_QUARTERS = .25,
VAL_GOAL = 1;
int pennies, nickels, dimes, quarters;
double totalValue = 1;
cout << "Enter How many pennies: " << endl;
cin >> pennies;
cout << "Enter How many nickels: " << endl;
cin >> nickels;
cout << "Enter How many dimes: " << endl;
cin >> dimes;
cout << "Enter How many quarters: " << endl;
cin >> quarters;
totalValue = ((VAL_PENNIES)*(pennies)+(VAL_NICKELS)*(nickels)+(VAL_DIMES)*(dimes)+(VAL_QUARTERS * (quarters)));
if (totalValue == VAL_GOAL){
cout << "You Win!" << endl;
}
else
{
cout << "You only have " << totalValue << endl;
}
return 0;
}
output
Success time:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.