Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Change for a Dollar Game
- // Jennifer Burgess
- // CSCI 193
- // Program 17
- // 6/28/14
- /* This program will play a dollar game with the user to enter the correct
- amount of coins that will add to a dollar and win the game.*/
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- int main()
- {
- // Declare Variables
- double quarters;
- double quartersTotal;
- double pennies;
- double penniesTotal;
- double dimes;
- double dimesTotal;
- double nickles;
- double nicklesTotal;
- double dollar;
- double total;
- // Initialize Variables
- quarters = 0; // Prompt user to input how many quarters
- pennies = 0; // Prompt user to input how many pennies
- dimes = 0; // Prompt user to input how many dimes
- nickles = 0; // Prompt user to input how many nickles
- total = 100; // The amount that all coins must add up to
- // Prompt User
- cout << "To win, enter how many quarters, dimes, nickles and pennies \n";
- cout << "are needed to make a dollar. " << endl;
- cout << "Enter how many quarters:" << endl;
- cin >> quarters;
- quartersTotal = quarters * 25;
- cout << "Enter how many dimes. " << endl;
- cin >> dimes;
- dimesTotal = dimes * 10;
- cout << "Enter how many nickles. " << endl;
- cin >> nickles;
- nicklesTotal = nickles * 5;
- cout << "Enter how many pennies. " << endl;
- cin >> pennies;
- penniesTotal = pennies * 1;
- dollar = quartersTotal + dimesTotal + nicklesTotal + penniesTotal;
- // Calculate data
- if (dollar == total)
- cout << "You won!" << endl;
- else if (dollar > total)
- cout << "Sorry, more than a dollar." << endl;
- else
- cout << "Sorry, less than a dollar." << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement