Concept explainers
Write a
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Starting Out With C++: Early Objects (10th Edition)
Additional Engineering Textbook Solutions
Problem Solving with C++ (9th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Absolute Java (6th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Java How To Program (Early Objects)
- You will write a program that calculates gas milage, also known as fuel economy. The program will use a while loop to repeatedly ask the user for the number of miles driven and gallons of gas used at their last fill up. On each iteration of the loop, your program will calculate the mileage for each fill up. The user will be able to exit the loop by pressing the enter key. After the user exits the loop, the program will print the cumulative gas mileage, by dividing the cumulative number of miles by the cumulative number of gallons. The floating point output should be printed to one decimal place of precision. Here is an example of how the program should work: Your Personal Fuel Economy Number of miles traveled (or enter to exit):380 Number of gallons needed: 12 Mileage this tank: 31.7 Number of miles traveled (or enter to exit): 235 Number of gallons needed:9 Mileage this tank: 26.1 Number of miles traveled (or enter to exit): Average mileage: 29.3arrow_forwardIn C, Write a statement that terminates the current loop when the value of the int variables x. and y are equalarrow_forwardThe while loop checks the loop-continuation-condition ______. Select one: a. First b. Last c. Continuously as the loop executes. d. Only when the loop-continuation-condition changes.arrow_forward
- True or False? In a do…while loop, the condition is checked at the bottom of the loop.arrow_forward2. Task 1: Using do-while loop Write a do-while loop which validate and evaluate the input value for variable grade. NOTE:The program will force the user to enter a valid grade.When the user enter a valid grade, the program will evaluate the grade as passing or failing grade.When the user enter an invalid grade, the program will only allow 3 invalid grade input.Valid grade is from 0 to 100 only.Passing grade is from 70 to 100.Failing grdae is from 0 to 69. NOTE:Your source code must display any of the given sample output below.It means your source code should be flexible enough to meet any of the given sample output.Your source code output must be identical to any of the given sample output.It means you have to strictly follow what are the displayed text, labels, casing of characters in the sample output. OUTPUT 1 Enter Grade: 100 Remark: Passed OUTPUT 2 Enter Grade: 69 Remark: Failed OUTPUT 3 Enter Grade: -1 Remark: Invalid Enter Grade: 101…arrow_forwardProblem 2: Safe Square Root Write a program to take the square root of a number typed in by the user. Your program should use a while-loop to ensure that the number they typed in is positive. If the number is negative, you should print out a warning “The number is negative. Try again.” and re-prompt the user to take a valid input. You can get the square root of a number n with Math.sqrt(n). Make sure you don't do this until the loop is done and you know for sure you've got a positive number. Sample input and output: Enter a number > -9 The number is negative. Try again. Enter a number > 9 The square root of 9 is 3.0 Enter a number > 2 The square root of 2 is 1.4142135623730951arrow_forward
- Overview This program will prompt a user for a start and a limit, it will then while-loop through, doubling the iterator each pass, until the limit is reached. Expected Output Example 1 Enter the start of the loop: Enter the limit of the loop: 25 The current value is 3 The current value is 6 The current value is 12 The current value is 24 The last value of current that was less than 25 was 24 Example 2 Enter the start of the loop: 25 Enter the limit of the loop: 102 The current value is 25 The current value is 50 The current value is 100 The last value of current that was less than 102 was 100 Specifications • You should submit a single file called M5A2.py • It should follow the submission standards outlined here: Submission Standards Your program populate an integer named start using input • Your program populate an integer named limit using input Your program must use an iterator named current Your program must move through the values using a while-loop Tips and Tricks That last…arrow_forwardpow(3,4)=? Select one: O a. 81 O b. 12 c. 64 O d. 7arrow_forwardThe continue statement in a while loop would be used to do what? O Reset the loop. Go back to the beginning of the loop. O Enter the loop. O Exit the loop.arrow_forward
- Use C++ programming language.. Random Number Guessing Game Write a program that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high. Try again.” If the user’s guess is lower than the random number, the program should display “Too low. Try again.” The program should use a loop that repeats until the user correctly guesses the random number. Then the program should display “Congratulations. You figured out my number.”arrow_forwardQuestion#2. The distance a vehicle travels can be calculated as fallout: Distance = Speed * Time For example, if a train travels 60 miles-per-hour for three hours, the distance [raveled is 120 miles. Write a program that asks for the speed of a vehicle (in miles-per-hour) and the number of hours it has traveled. It should use a loop to display the distance a vehicle has traveled for each hour of a time period specified by the user. For example, if a vehicle is traveling at 40 mph far a three-hour time period, it should display a report similar to the one chat follows: Hour Distance Traveled 1 90 2 100 3 150 Input Validation: Do not accept a negative number for speed and do not accept any value les than 1 for time traveled.arrow_forwardC++arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning