A liter is 0.264179 gallons. Write a
List of variables:
number_of_miles: Store the number of miles travelled.
liter_of_gas: Store the quantity of gasoline consumed.
List of functions used:
cout.setf(ios::showpoint): For controlling the floating and trailing zeros.
cout.precision(2): Dislay the values up to two digits.
cin(): To take input from input streams like keyboard, files etc.
cout(): To display the output.
Summary Introduction:
Program will use the Main () method to prompt the user to enter the number of miles traveled and the number of gasoline consumed to find the number of miles per gallon car delivered. A liter is equal to 0.264179 gallons.
Program Description:
The purpose of the program is to find the number of miles per gallon car delivered.
Explanation of Solution
Program:
Following is the C++ program to find the number of miles per gallon car delivered.
/*
* Program: The program asks user to provide the number of miles car travelled and the amount of gasoline consumed to find the number of miles per gallon car delivered.
*/
#include <iostream> Usingnamespacestd; constdouble LITRE =0.264179; // A liter is equal to 0.264179 gallons doublemiles_per_gallons(float,float); intmain(){ cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); charans; do{ // declare the variables. Floatnumber_of_miles,liter_of_gas; cout<<"Enter the number of miles traveled: "; cin>>number_of_miles; cout<<"\nEnter the number of liters of gasoline consumed: "; cin>>liter_of_gas; cout<<endl<<miles_per_gallons(number_of_miles,liter_of_gas); cout<<endl<<"Do you want to calculate again? "; cin>>ans; }while(ans=='Y'||ans=='y'); cout<<"\nThank You!"; return0; } // function to calculate the miles per gallon car delivered. doublemiles_per_gallons(floatnumber_of_miles,floatliter_of_gasoline){ returnnumber_of_miles/(liter_of_gasoline*LITRE); }
Explanation:
The above program prompts the user to enter the number of miles traveled and the number of gasoline consumed and after that function miles_per_gallons() is defined to find the number of miles traveled by gasoline consumed in liter. Then cout() function is used to show the output of the program.
Sample Output:
Following is the sample output for the given program:
Enter the number of coupons: 25 The number of Candy bars: 2 The number of Gum Balls: 1 The remaining coupons are: 2
Want to see more full solutions like this?
Chapter 3 Solutions
Absolute C++
Additional Engineering Textbook Solutions
Problem Solving with C++ (10th Edition)
Absolute Java (6th Edition)
Starting Out with C++: Early Objects (9th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with C++: Early Objects
Starting Out with Python (4th 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