A liter is 0.264179 gallons. Write a
- Include required header files.
- Declare and initialize a constant value “lpg = 0.264179”.
- Define a function named “calc()” to calculate “milage”.
- Declare a variable “gal”.
- Compute “gal” and “milage”
- Function to return “milage”.
- Define a “main()” function.
- Declare the variables “lit” and “miles”.
- Declare a variable “ch”.
- “do… while” loop to get the user input repeatedly.
- Get the “lit” and “miles” from the user.
- Call “calc()” with an arguments “lit” and “miles” values and print the “milage”.
- Get the user input to repeat the program or not.
- The input is checked with the condition and repeat or exit the program.
Explanation of Solution
Program to compute number of miles per gallon the car delivered:
// Include required header files
#include <iostream>
using namespace std;
// Assign const value
float const lpg=0.264179;
// Function definition of calc()
float calc(float liters, float miles)
{
// Declare gal
float gal;
// Compute gal
gal = lpg * liters;
// Compute milage
float milage = miles/gal;
// Return milage
return(milage);
}
// Function definition of main()
int main()
{
// Declare lit and miles
float lit, miles;
// Declare ch
char ch;
// do... while loop
do{
// Get the liters
cout<<"\nEnter the number of liters of gasoline: ";
// Assign the user input to lit
cin>>lit;
// Get the miles
cout<<"\nEnter the number of miles Travelled: ";
// Assign the user input to miles
cin>>miles;
// Display the miles per gallon the car delivered
cout<<"\nNumber of miles per gallon the car delivered: ";
// Call the function cal() and return the result
cout<< calc(lit, miles) << endl;
// Get the user input
cout<<"\nDo you want to repeat(y/n)??: ";
// Assign the user input to ch
cin>>ch;
// While loop condition to check ch is equal to y
}while(ch=='y' || ch=='Y');
// Return 0
return 0;
}
Enter the number of liters of gasoline: 5
Enter the number of miles Travelled: 30
Number of miles per gallon the car delivered: 22.7119
Do you want to repeat(y/n)??: n
Want to see more full solutions like this?
Chapter 4 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Thinking Like an Engineer: An Active Learning Approach (4th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
SURVEY OF OPERATING SYSTEMS
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Java: An Introduction to Problem Solving and Programming (8th Edition)
- In this question you need to write a program and execute it with the given input, the output of your code is the answer to this question and in the next question paste your code. Write a function GregorianConvíyear) that takes a Islamic(Lunar) year, then returns the corresponding Gregorian year. You have to TEST that the input is a valid number in the range of 1300 to the current year 1442.Year Gregorian = (Year Muslim ) / 0.97 + 622, Note: as the two calendars don't start from the same month, year 2021 corresponds to the years 1442-1443 in the Islamic calendar. So round your solution. What will be the Gregorian year for the Islamic year 1320? Answer:arrow_forwardpythonarrow_forwardOne lap around a standard high-school running track is exactly 0.25 miles. Define a function named laps_to_miles that takes a number of laps as a parameter, and returns the number of miles. Then, write a main program that takes a number of laps as an input, calls function laps_to_miles() to calculate the number of miles, and outputs the number of miles. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: print (f' {your_value:.2f}') Ex: If the input is: 7.6 the output is: 1.90 Ex: If the input is: 2.2 the output is: 0.55 The program must define and call the following function: def laps_to_miles (user_laps) 461710.3116374.qx3zqy7 LAB ACTIVITY 1 # Define your function here 21 3 00 Jo UAWN P 4 if ___name__ 5 6 7.8.1: LAB: Track laps to miles 7 8 main.py '__main__': # Type your code here. Your code must call the function. 8/10 Load default template...arrow_forward
- One lap around a standard high-school running track is exactly 0.25 miles. Define a function named laps_to_miles that takes a number of laps as a parameter, and returns the number of miles. Then, write a main program that takes a number of laps as an input, calls function laps_to_miles() to calculate the number of miles, and outputs the number of miles. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: print (f'{your_value:.2f}') Ex: If the input is: 7.6 the output is: 1.90 Ex: If the input is: 2.2 the output is: 0.55 The program must define and call the following function: def laps_to_miles (user_laps) 461710.3116374.qx3zqy7 LAB ACTIVITY 7.8.1: LAB: Track laps to miles 1 # Define your function here 2 3 if __name__ 4 main.py == '__main__': #Type your code here. Your code must call the function. 0/10 Load default template...arrow_forwardOne lap around a standard high-school running track is exactly 0.25 miles. Define a function named laps_to_miles that takes a number of laps as a parameter, and returns the number of miles. Then, write a main program that takes a number of laps as an input, calls function laps_to_miles() to calculate the number of miles, and outputs the number of miles. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: print (f' {your_value:.2f}') Ex: If the input is: 7.6 the output is: 1.90 Ex: If the input is: 2.2 the output is: 0.55 The program must define and call the following function: def laps_to_miles (user_laps) 461710.3116374.qx3zqy7 LAB ACTIVITY 1 # Define your function here 2 456WNI 3 4 7.8.1: LAB: Track laps to miles 6 main.py 5 # Type your code here. Your code must call the function. 8/10 Load default template...arrow_forwardA "jiffy" is the scientific name for 1/100th of a second. Define a function named jiffies_to_seconds that takes the number of "jiffies" as a parameter, and returns the number of seconds. Then, write a main program that reads the number of jiffies (float) as an input, calls function jiffies_to_seconds() with the input as argument, and outputs the number of seconds. Output each floating-point value with three digits after the decimal point, which can be achieved as follows:print(f'{your_value:.3f}') Ex: If the input is: 15.25 the output is: 0.152 The program must define and call the following function: def jiffies_to_seconds(user_jiffies) MY CODE: def jiffies_to_seconds(user_seconds): jiffies = user_seconds*100 return jiffies #main of programif __name__ == '__main__': user_seconds = float(input()) jiffies = jiffies_to_seconds (user_seconds) print(f'{user_seconds:.3f}') ERROR: Not understanding the correct function here. The output is putting the decimal in the wrong…arrow_forward
- The following program will prompt the user for a starting number and an // ending number. Assume that these are whole numbers (no decimal points), // assume the numbers are not negative and assume that the first number is // not larger than the second number. // // write a funcTion that returns the sum of the numbers from the starting // number to the ending number. For example, if the starting number is 13 // and the ending number is 18 then the function will return the value of // 13 + 14 + 15 + 16 + 17 + 18. If the starting number is equal to the ending // number then simply return that number. // ////////////////////////////////////////////////////////////////////////// function sumOfNumbers(startingNumber, endingNumber) { } var startingNumber = parseInt(prompt('What is the starting number? ')); var endingNumber = parseInt(prompt('What is the ending number? ')); var sumOfNumbersPassed = sumOfNumbers(startingNumber, endingNumber); alert('The sum of the numbers from ' +…arrow_forwardWrite a function that computes the average of the digits in an integer. Use the following function header: double averageDigits(long n)arrow_forwardanswer this question in Pythonarrow_forward
- One lap around a standard high-school running track is exactly 0.25 miles. Define a function named LapsToMiles that takes a double as a parameter, representing the number of laps, and returns a double that represents the number of miles. Then, write a main program that takes a number of laps as an input, calls function LapsToMiles() to calculate the number of miles, and outputs the number of miles. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: printf("%0.21f\n", yourValue); Ex: If the input is: 7.6 the output is: 1.90 Ex: If the input is: 2.2 the output is: 0.55 The program must define and call a function: double LapsToMiles (double userLaps) 412800.2778464.qx3zqy7 LAB ACTIVITY 1 #include 2 3 /* Define your function here */ 4 6.20.1: LAB: Track laps to miles 8 5 int main(void) { 6 7 /* Type your code here. Your code must call the function. */ 9 10 11 main.c return 0; 0/10 Load default template...arrow_forwardWrite a program that accepts as input: a.)miles you have driven b.)miles per gallon, car efficiency c.)gas cost per gallon. Your program the invokes the XXX( ) function which computes and returns how many gallons of gas you have consumed to drive those miles. Then your main program continues and computes the cost of the consumed gas and displays that cost. See below. Replace the XXX ( ) function name with whatever name you want and decide about the parameters. Output each floating-point value with two digits after the decimal point, which can be achieved as follows:print(f'{your_value:.2f}')arrow_forwardin Python Write a function named LowerNDigits(x,y), which takes two integeres x and y as input parameter and returns y least significant digit the number x, for an example : if x = 4237 and y = 2, then LowerNDigits(x,y) should return 37 as these are 2 least significant digits for x if x = 1293 and y = 3, then LowerNDigits(x,y) should return 293as these are 3 least significant digits for xarrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr