Question

In: Computer Science

C++: Write a program to convert from gallons to liters. The program should allow the user...

C++: Write a program to convert from gallons to liters. The program should allow the user to input the amount with decimal places and then see the result on the screen.

Solutions

Expert Solution

Dear Learner,

Here is the C++ code for converting gallons to liters.

NOTE:- the formula for converting used in the code is 1 (US)Gallon = 3.78541 Liters

CODE:

#include<iostream>
using namespace std;

main()
{ float gallons,liters; //variables to store the quantities
cout<<"Enter the quantity in gallons :"; //asking the user to enter the volume in gallons
cin>>gallons; //storing the input in 'gallons' variable. NOTE that the float datatype will allow the user to enter amount with decimal places
liters = 3.78541 * gallons; //calculating corresponding liters
cout<<"\n"<<gallons<<" gallons = "<<liters<<" liters"; //displaing the result
}

SCREENSHOT:

OUTPUT:

I hope I have answered the question the way you were expecting. If you still have any doubts or want any other explanation, feel free to ask us in the comments.

Please leave a like if this was helpful.

Thanks,

Happy Studying.


Related Solutions

Write a C++ program that : 1. Allow the user to enter the size of the...
Write a C++ program that : 1. Allow the user to enter the size of the matrix such as N. N must be an integer that is >= 2 and < 11. 2. Create an vector of size N x N. 3. Call a function to do the following : Populate the vector with N2 distinct random numbers. Display the created array. 4. Call a function to determines whether the numbers in n x n vector satisfy the perfect matrix...
Create design document for a program that will allow the user: Convert a number to binary....
Create design document for a program that will allow the user: Convert a number to binary. Convert from binary to number. Display the hexadecimal representation of a binary number. Given an hexadecimal display its binary representation. Convert a number to IEEE single precision and vice versa. More to come. PLEASE ADD PSEUDOCODE AND USE C PROGRAMMING USE FUNCTIONS IF POSSIBLE
Write a program that read the input from user and convert it to binary and hex...
Write a program that read the input from user and convert it to binary and hex in C language.
Write a C++ program to allow the user to: 1. Create two classes. Employee and Departments....
Write a C++ program to allow the user to: 1. Create two classes. Employee and Departments. The Department class will have: DepartmentID, Departmentname, DepartmentHeadName. The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID. Both of the above classes should have appropriate constructors, accessor methods. 2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3. Your program should display a menu for the user to do the following: 1....
Write a C++ program to allow a user to enter in any positive number greater than...
Write a C++ program to allow a user to enter in any positive number greater than or equal to zero. The program should not continue until the user has entered valid input. Once valid input has been entered the application will determine if the number is an abundant number or not and display whether or not the number is an abundant number. If the user enters in a 0 the program should quit. An abundant number is a number n...
write a program to perform the following in C Your program should prompt the user to...
write a program to perform the following in C Your program should prompt the user to enter ten words, one at a time, which are to be stored in an array of strings. After all of the words have been entered, the list is to be reordered as necessary to place the words into alphabetical order, regardless of case. Once the list is in alphabetical order, the list should be output to the console in order. The program should execute...
Write a Visual C# project that will allow the user an option to choose from four...
Write a Visual C# project that will allow the user an option to choose from four different countries. When a country is chosen, the program will display the country flag and information that the user wishes to see. The name of the country selected will be displayed in a label under the country's flag image. The user may also choose to display or hide the form's title, the country name, and the name of the programmer/developer.   Check boxes will be...
Write a python program that will allow a user to draw by inputting commands. The program...
Write a python program that will allow a user to draw by inputting commands. The program will load all of the commands first (until it reaches command "exit" or "done"), and then create the drawing. Must include the following: change attributes: color [red | green | blue] width [value] heading [value] position [xval] [yval] drawing: draw_axes draw_tri [x1] [y1] [x2] [y2] [x3] [y3 draw_rect [x] [y] [b] [h] draw_poly [x] [y] [n] [s] draw_path [path] random random [color | width...
write a c++ program that prompts a user to enter 10 numbers. this program should read...
write a c++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the two numbers and the average of the 10 numbers PS use file I/o and input error checking methods
In Java: Write a program called F2C that allows the user to convert from degrees Fahrenheit...
In Java: Write a program called F2C that allows the user to convert from degrees Fahrenheit to degrees Celsius. The program should prompt for a temperature in Fahrenheit and output a temperature in Celsius. All calculations should be done in in ints, so be careful of truncation.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT