Computer Science > STUDY GUIDE > NETWORK+ G itnw 1325chapter-4-programming-challengesnotassigned (All)
Chapter 4 Programming Challenges, Questions not assigned 5. Book Club Points An online book club awards points to its customers based on the number of books purchased each month. Points are awarded... as follows: Books purchased Points earned 0 0 1 5 2 15 3 30 4 or more 60 // Chapter 4 - Programming Challenge 5, Book Club Points #include <iomanip> using namespace std; int main() { int numBooks, // Number of books purchased in a month points; // Number of points earned // Input the number of books purchased cout << "How many books did you purchase through the book club this month? "; cin >> numBooks; // Determine the number of points awarded if (numBooks <= 0) points = 0; else if (numBooks == 1) points = 5; else if (numBooks == 2) points = 15; else if (numBooks == 3) points = 30; else // numBooks must be 4 or more points = 60; // Display the result cout << "You earned " << points << " points this month. \n"; return 0; } Write a program that asks the user to enter the number of books purchased this month and then displays the number of points awarded. 6. Change for a Dollar Game 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 thetotal 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. Input Process Output Pennies, dimes, nickels, quarters Dollar=(pennies*.01+dimes*.10+nickels*.05+quarters*.25) Dollar notdollar // Chapter 4 - Programming Challenge 6, Change for a Dollar Game // This program challenges the user to enter a combination of coins // that equals exactly one dollar. #include <iostream> using namespace std; int main() { const double PENNY_VALUE = .01, NICKEL_VALUE = .05, DIME_VALUE = .10, QUARTER_VALUE = .25, GOAL = 1.00; int numPennies, numNickels, numDimes, numQuarters; double total; // Input the number of each denomination to use. cout << "The goal of this game is to enter a combination of quarters,\n" << "dimes, nickels, and pennies that add up to exactly one dollar. \n\n"; cout << "How many quarters should I use? "; cin >> numQuarters; cout << "How many dimes should I use? "; cin >> numDimes; cout << "How many nickels should I use? "; cin >> numNickels; cout << "How many pennies should I use? "; cin >> numPennies; total = numQuarters * QUARTER_VALUE + numDimes * DIME_VALUE + numNickels * NICKEL_VALUE + numPennies * PENNY_VALUE; if (total > GOAL) cout << "\nYour coins total $" << total << ". That is more than a dollar. \n"; else if (total < GOAL) cout << "\nYour coins total $" << total << ". That is less than a dollar. \n"; else cout << "\nCongratulations. Your coins total exactly a dollar. \n"; return 0; } 7. Time CalculatorWrite a program that asks the user to enter a number of seconds. • There are 86400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86400, the program should display the number of days in that many seconds. • There are 3600 seconds in an hour. If the number of seconds entered by the user is less than 86400, but is greater than or equal to 3600, the program should display the number of hours in that many seconds. • There are 60 seconds in a minute. If the number of seconds entered by the user is less than 3600, but is greater than or equal to 60, the program should display the number of minutes in that many seconds. // Chapter 4 - Programming Challenge 7, Time Calculator // This program converts seconds to days, hours, or minutes, // whichever is most appropriate. #include <iostream> #include <iomanip> using namespace std; int main() { const int SEC_PER_DAY = 86400, // Number of seconds in a day SEC_PER_HOUR = 3600, // Number of seconds in an hour SEC_PER_MINUTE = 60; // Number of seconds in a minute double seconds; // Length of time measured in seconds // Input the number of seconds cout << "This program will convert seconds to days, hours, or minutes. \n\n"; cout << "Enter the number of seconds (60 or more): "; cin >> seconds; // Set the output format cout << fixed << setprecision(2); [Show More]
Last updated: 2 years ago
Preview 1 out of 17 pages
Buy this document to get the full access instantly
Instant Download Access after purchase
Buy NowInstant download
We Accept:
Can't find what you want? Try our AI powered Search
Connected school, study & course
About the document
Uploaded On
May 28, 2021
Number of pages
17
Written in
This document has been written for:
Uploaded
May 28, 2021
Downloads
0
Views
63
In Scholarfriends, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Scholarfriends · High quality services·