Concept explainers
Write a program that outputs the lyrics for the song “Ninety-Nine Bottles of Beer on the Wall.” Your program should print the number of bottles in English, not as a number. For example:
Ninety-nine bottles of beer on the wall,
Ninety-nine bottles of beer.
Take one down, pass it around,
Ninety-eight bottles of beer on the wall.
...
One bottle of beer on the wall,
One bottle of beer,
Take one down, pass it around,
Zero bottles of beer on the wall.
Design your program with a function that takes as an argument an integer between 0 and 99 and returns a string that contains the integer value in English. Your function should not have 100 different if-else statements! Instead, use % and / to extract the tens and ones digits to construct the English string. You may need to test specifically for values such as 0, 10–19, etc.
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Modern Database Management
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
Elementary Surveying: An Introduction To Geomatics (15th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
- (Program) Write a program to simulate the rolling of two dice. If the total of the two dice is 7 or 11, you win; otherwise, you lose. Embellish this program as much as you like with betting, different odds, different combinations for win or lose, stopping play when you have no money left or reach the house limit, displaying the dice, and so forth. (Hint: Calculate the dots showing on each die with theexpressiondots=(int)(6.0randomnumber+1), where random number is between 0 and 1.)arrow_forwardWrite a program that takes a positive integer as the height of the triangle and prints an alphabetical triangle, using lowercase English letters as shown below. Each subsequent row of the triangle should increase in length by two letters. Make sure your program validates the user input. If the user does not input a positive integer, print "Invalid input."arrow_forwardWrite a program that prints the numbers from 1 to 100, except if the number is divisible by 3 print 'Beep' instead of the number and if it is divisible by 5 print 'Boop'. For numbers which are divisible by both 3 and 5 print 'BeepBoop'. (See the output below: 3 and 6 are replaced by 'Beep'; 5 and 10 are replaced by 'Boop'; 15 and 30 are replaced by 'BeepBoop') Use a for loop.arrow_forward
- Using Paython Write a program that asks a student for his grade (out of 100) in 3 exams and then print out his final grade (out of 100), given that the weight of the first exam is 30%, the second 30%, and the third 40%.Example Input:Exam1: 70Exam2: 80Exam3: 90Example Output:Total Grade = 81Explanation: 0.3 * 70 + 0.3 * 80 + 0.4 * 90 = 81arrow_forwardWrite a program that asks you to input an integer. After you input the integer, it should ask if you want to input another integer. If you answer y, it should allow you to input a second integer and then output the sum of the two integers you entered. If you answer n or some character other than y, it should output the integer you input before. For example: if you input 4, answer y and then input 3, it should output 7 if you input 4 and answer n, it should output 4arrow_forwardWrite a program to get a random number between 1 and 100, use the button to check whether the given number is even or odd. Display it is odd or even with the number. Ask from the user how many numbers theywant to check based on that get the number from the user and checkarrow_forward
- Write a program that asks the user how many credit units they have taken. If they have taken 23 or less, print that the student is a freshman. If they have taken between 24 and 53, print that they are a sophomore. The range for juniors is 54 to 83, and for seniors it is 84 and over.arrow_forwardIn order to discourage excess electric consumption, an electrical company charges its customers a lower rate of P75 for the first 250 kilowatt-hours and a higher rate of P8.5 for each additional kilowatt-hour. In addition, a 10% surtax is added to the final bill. Write a program that calculates the electrical bill given the number of kilowatt-hours consumed as input. At the end, print the number of kilowatt- hours consumed and the computed bill. For example: Input Result 200 Kilowatt -hours: 200 Electric bill: Php 82.50 260 Kilowatt-hours: 260 Electric bill: Php 176.00arrow_forwardWrite a program that generates a plate number based on the user's answer to the following questions: 1. What is your favorite color of the rainbow (ROYGVIB)? a. Use the first letter of the chosen color as the first character of the plate number. b. Display "Invalid Input" and ask the user to re-enter his/her answer if the answer is not a valid color of the rainbow. 2. What is your month of birth? a. Use the last letter of the month as the second character of the plate number. b. Display "Invalid Input" and ask the user to re-enter his/her answer if the answer is not a valid month. 3. What is your first name? a. Use the third letter of the first name as the third character of the plate number. No need to include the second name if you have a second name. Make sure to use "cout" and "cin" to collect the necessary inputs from the user. For the number section: 1. Ask the user his/her age and use the age as the first and second digits of the plate number. a. Display "Invalid Input" and ask…arrow_forward
- Write a program to calculate the net pay of an employee. Input the basic pay and calculate the net pay as follows: House rent is 45% of basic pay. Medical allowance is 2% of basic pay if basic pay is greater than Rs. 5000/-. It is 5% of basic pay if the basic pay is less than Rs. 5000/-. Conveyance allowance is Rs. 96/- if basic pay is less than Rs. 5000/-. It is Rs. 193/- if the basic pay is more than Rs. 5000/- Net pay is calculated by adding basic pay, medical allowance, conveyance allowance and house rant. using ooparrow_forwardA parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an additional $0.50 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24 hours at a time. Write a program that calculates and prints the parking charges for each of three customers who parked their cars in this garage yesterday. You should enter the hours parked for each customer. Your program should print the results in a neat tabular format and should calculate and print the total of yesterday’s receipts. The program should use the function calculateCharges to determine the charge for each customer. Your outputs should appear in the following format Sample output Enter the hours parked for 3 cars: 1.5 4.0 24.0 Car Hours Charge 1 1.5 2.00 2 4.0 2.50 3 24.0 10.00 TOTAL 29.5 14.50arrow_forwardCreate a program that asks a character input. If the character input is 'Y', then it prints "Continuing..." and asks user for a character input again. If the character input is 'X', then it prints "Exiting..." and stops the program. An initial code is provided for you. Just fill in the blanks. Input 1. One or more line (s) containing a character. Sample Y Y X Output Enter choice (X/Y): Y Continuing... Enter choice (X/Y): Y Continuing... Enter choice (X/Y): -X Exiting... ► Main.java 1 2 3 vv class Main { Avv 5 6 7 vv LO 8 600 9 10 11 import java.util.Scanner; } public static void main(String[] args) { char input; do { } while (input != 'X');arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr