1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Lilit [14]
3 years ago
8

Create a change-counting game that asks the user to enter what coins to use to make exactly one dollar. The program should ask t

he user to enter the number of pennies, nickels, dimes, and quarters. If the total value of the coins entered 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.
Computers and Technology
1 answer:
Mashutka [201]3 years ago
5 0

Answer:

The cpp program is given below.

#include <stdio.h>

#include <iostream>

using namespace std;

int main()

{

   //constant variables holding values of coins

   const int penny=1;

   const int nickel=5;

   const int dime=10;

   const int quarter=25;

   //variables to hold user input of number of coins

   int p, n, d, q, sum;

   std::cout << "Enter the number of pennies: ";

   cin>>p;

   std::cout << "Enter the number of nickels: ";

   cin>>n;

   std::cout << "Enter the number of dimes: ";

   cin>>d;

   std::cout << "Enter the number of quarters: ";

   cin>>q;

   //total amount is computed

   sum=penny*p;

   sum=sum+(nickel*n);

   sum=sum+(dime*d);

   sum=sum+(quarter*q);

   if(sum==100)

       std::cout << "Congratulations! You won the game." << std::endl;

   else

   {

       if(sum<100)

           std::cout << "Your entered amount was less by " <<(100-sum)<< " cents. " <<std::endl;

       else

           std::cout << "Your entered amount was more by " <<(sum-100) << " cents. "<< std::endl;

   }

   return 0;

}

OUTPUT

Enter the number of pennies: 1

Enter the number of nickels: 1

Enter the number of dimes: 1

Enter the number of quarters: 1

Your entered amount was less by 59 cents.

Explanation:

1. All the values of the coins, penny, nickel, dime and quarter are declared as constant integers.

2. The variables are declared to hold user input for the number of coins of all the constant denominations.

3. Once the user enters the required values, total sum of all the coins entered by the user is computed.

4. If the total value of the coins equals 100 cents, user won the game since the user entered correct values which summed up to 100 cents or 1 dollar.

5. If the total value of the coins does not equals 100 cents, the total is either less or more than 100 cents. The required difference between the user entered coins and 1 dollar is displayed to the user and the user loses the game.

6. The entire logic for user input is placed inside main() method.

7. All the variables and constants are also declared and defined respectively inside main() method.

You might be interested in
Is doing free lancing from age 16 good or bad?​
Art [367]

Answer:

I think it's good. It will serve as an experience for you. Having experience at an early age is better as you could be at your best before you go into the field that you want. Plus free lancing wouldnt tie you down, gives you more freedom. And extra income(?). ^^

8 0
3 years ago
Describe the role of a distributed file system in a job execution environment such as MapReduce in a large-scale cloud system. g
Bezzdna [24]

Answer:

allows users of physically distributed systems to share their data and resources

Explanation:

The main purpose of the Distributed File System (DFS) is to allows users of physically distributed systems to share their data and resources

6 0
2 years ago
A powerful computer that acts as a hub for other computers is a called a ______.
zhannawk [14.2K]
It is called a server
7 0
3 years ago
Read 2 more answers
PHOTOGRAPHY
Natasha_Volkova [10]

Answer:

false

Explanation:

when you zoom in it mkes it bigger and closer not smaller and farther

hope this helps :)

8 0
3 years ago
Read 2 more answers
Which of the following techniques would a Baroque composer most likely employ to evoke an affect of agitation? Select one:
frez [133]

Answer:

b. Rubato tremolo

Explanation:

Tremolo is a modulation effect that imposes a rhythmic change in volume of sound. Once discovered in electric amplifier circuits, sound engineers and composers like the Baroque now use this low frequency oscillating modulation technique to create emotional piercing effect on their audience to maintain focus.

The low frequency tremolo can be gotten from the vibrating string in guitars, violins etc, and vocal sound, it is also produced from electronic devices created for its purpose. they are called optical tremolo.

5 0
4 years ago
Other questions:
  • Describe two measures you can use to evaluate whether an attachment in a message is reliable to open.
    8·2 answers
  • Show what this program prints. Be exact and complete. Can you explain the behavior of each print statement? 1 2 3 4 5 6 7 public
    12·1 answer
  • Which directory in the FHS stores programs and configuration information that can only be executed and modified by the root user
    10·1 answer
  • When advising a customer on the purchase of a new power supply, you should explain that if the power supply runs at peak perform
    9·1 answer
  • William has an internet connection that does not allow him to make calls when connected to the internet. what internet service c
    7·2 answers
  • Which PowerShell command will upgrade the VM configuration version to take advantage of the new features in Windows Server 2016?
    12·1 answer
  • the command prompt window should be avoided because it is dangerous to do commands there? True or false
    14·1 answer
  • Why do i have to wait and watch videos
    11·1 answer
  • The web server administrator at your e-commerce company is concerned about someone using netcat to connect to the company web se
    11·1 answer
  • Write a flowchart and program that does the following: Asks the user for the average temperature in each of the last 12 months A
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!