Concept explainers
Suppose savings and expenses are variables of type double that have been given values. Write an if-else statement that outputs the word Solvent, decreases the value of savings by the value of expenses, and sets the value of expenses to 0, provided that savings is at least as large as expenses. If, however, savings is less than expenses, the if-else statement simply outputs the word Bankrupt and does not change the value of any variables.
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Problem Solving with C++, Student Value Edition Plus MyLab Programming with Pearson eText - Access Card Package (10th Edition)
Additional Engineering Textbook Solutions
Starting out with Visual C# (4th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Starting Out with C++: Early Objects (9th Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
Starting Out With Visual Basic (8th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
- Write a program that works out if a given year is a leap year This is how to workout whether if a perticular year is a leap year on every year that is evenly divisible by 100 except every year that is evenly divisible by 100 unless the year is also evenly divisible by 400 Note Study the flow chart given below START No Yesit cleanly divisible by Not Leap No Yes it cleanly divisible by 1007 Leap No Yes it cleanly divisible by 4007 Not Leap Leap Guideline : Create a unique code Create a function leapYear_697 to accept the parameter (i.e year ) and return whether the given year is a leap year Javascript program name should be like Assign2 697arrow_forwardWrite a program that can accept two inputs - a food type and a price, and determines if the food is affordable or expensive. This program should use an if-statement to determine. If the cost of the food is over $20, then the program should say it is expensive, and otherwise it should say it is affordable (this is arbitrary - for the purposes of making this problem simple).arrow_forwardWrite a program that given an amount of change less than $1.00 will print out exactly how many quarters, dimes, nickels, and pennies will be needed to efficiently make that change. [Hint: the // operator may be useful.]arrow_forward
- Create a Sample Code using Java If Else Statement Problem Here's the given:If - Good Morningelse if - A pleasant morning else - Have a pleasant morning Output: Have a pleasant morningarrow_forwardImplement the following: 1) Request a user input for the variable, direction.2) Write an if-elif-else statement to do the following: a) if the direction is 'N', print a message, North Zone. b) if the direction is 'S', print a message, South Zone. c) if the direction is 'E', print a message, East Zone. d) if the direction is 'W', print a message, West Zone. e) if the direction is none of the above, print a message, Invalid Input. f) uppercase and lowercase should be all acceptable. Example Output 1Enter your direction(N/S/E/W): uptownInvalid Input. Example Output 2Enter your direction(N/S/E/W): eEast Zone. NEED HELP WITH PYTHON CODEarrow_forwardGiven four positive integers a, b, c, and d, compute the sum of those among them that are odd. Because you have not yet learned how to make decisions, use the fact that for a positive integer n, the expression n % 2 is either 0 or 1. (not allowed to use an if statement or conditonal)arrow_forward
- Write a program that will figure out the required change for a purchase. Start by asking the user for the price of the product and the amount paid. (We are expecting that the user will give a larger value for the amount paid.) Read in each of these values as a double. Report back to the user the number of each denomination of change due. You are not just telling the user the amount of money he gets back. Hint: Working with integers is much easier. The modulo operator is your friend for this assignment. Also, note that pennies can be tricky due to the poor real number to binary conversions. (Remember that 1.00 could actually be stored as 0.9999999999997.) Do not include five-dollar bills, ten-dollar bills, etc. Only show coins and one-dollar bill amounts. Be sure to test multiple values. There is a test case below. Your program should run the test case exactly as it appears below, and should work on any other case in general. Output Example (User input is marked with >>>.…arrow_forwardWrite a program using if-else statements that convert from lbs to kg and vice versa. The input should be type (Lbs or Kg) and a number. The output of the program must be as shown in the examples below. Example 1: Input: Enter your weight: 50 (L)bs or (K)g: L Output: You are 22.5 kilos Example 2: Input: Enter your weight: 50 (L)bs or (K)g: K Output: You are 111.11 pounds Example 3: Input: Enter your weight: 50 (L)bs or (K)g: k Output: Either of your inputs are invalid! pythonarrow_forwardWrite a code using C++ for the given prompt: A contractor orders, say, 30 cubic yards of premixed concrete to construct a patio that is to be, say, four inches thick. The length of the patio is to be, say, twice the width. Write a program that prompts the user to specify: The amount of premixed concrete (in cubic yards) ordered The thickness of the patio (in inches) The ratio of length and width Ex. If the ratio is 3 to 2, have the program accept a 3 then a 2. Then compute the ratio using these numbers The program then outputs: The length and width of the patio (in feet). (1 cubic yard = 27 cubic feet.) To calculate the width, you will need to: Find the total cubic feet of the concrete Divide the total cubic feet of concrete by the result of the length to width ratio multiplied by the thickness of the patio, over 12 (inches in a foot) Square root the answer To find the square root of a decimal number, include the header file cmath using the statement #include <cmath>,…arrow_forward
- The question asks me to write out a cascaded or nested if program that will, if a "premium member", will assign 1 free book for a 5 or more book purchase and 2 free books for a purchase of 8 or more books. For a regular customer, a purchase of 7 or more books means 1 free book and a purchase of 12 or more books means 2 free books. For this question I have to use variables isPremiumCustomer to determine if the customer is a premium member, nbooksPurchased to determine how many books were purchased, and freeBooks to determine how many free books a customer will recieve. I am using Python for this question.arrow_forwardWrite an if-else statement with multiple branches.If year is 2101 or later, print "Distant future" (without quotes). Otherwise, if year is 2001 or greater, print "21st century". Otherwise, if year is 1901 or greater, print "20th century". Else (1900 or earlier), print "Long ago".Sample output with input: 1776 Long agoarrow_forwardLet's modify the program from this section so that the user can supply the interest rate. For very small interest rates, it may take a very long time for the balance to double. Assume the user can't wait for more than twenty years. Stop adding interest when the balance has doubled or twenty years have elapsed. 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 finaldoubleTARGET=2*INITIAL_BALANCE; doublebalance=INITIAL_BALANCE; intyear=0; Scannerin=newScanner(System.in); System.out.print("Interest rate in percent: "); doublerate=in.nextDouble(); // TODO: Count the years required for the investment to double // but no more than 20 years /* Your code goes here */ System.out.println("Year: "+year); System.out.printf("Balance: %.2f%n", balance); }arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education