Allow the user to enter a decimal number which will represent the number of gall
ID: 3678990 • Letter: A
Question
Allow the user to enter a decimal number which will represent the number of gallons of gasoline and then convert them to liters. 1 gallon is equivalent to 3.7854 liters. Sample Interaction Please enter the number of gallons of gasoline: 100 Original number of gallons is 100 100 gallons is the equivalent of 378.54 liters Thanks for playing Allow the user to enter the initial of their first name and display a triangle using die letter that was entered by the user The character displayed must be the one that was entered by the user For example, if the user enters the D then your output should look as followsExplanation / Answer
Here I am assuming that the languarge of implementation is C++
1)
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main ()
{
int no_of_gallons;
float litres_amt; //final amount in litre
cout<<"Please enter the number of gallons of gasoline"<<endl;
cin>> no_of_gallons; //reading from user
cout<<"Original number of gallons is: "<< no_of_gallons<<endl;
litres_amt = 3.7854 *no_of_gallons;//calculating amount in litre
cout<<no_of_gallons<<" gallons is the equivalent of "<<litres_amt<<"litres "<<endl;
cout<<"Thanks for playing";
}
Sample Input and Output:
Please enter the number of gallons of gasoline
100
Original number of gallons is: 100
100 gallons is the equivalent of 378.54litres
2)
code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main ()
{
char c;
cout<<"Please enter the initial character of your first name"<<endl;
cin>> c; //reading from user
cout<<" "<<c<<" "<<endl;
cout<<" "<<c<<" "<<c<<endl;
cout<<" "<<c<<" "<<c<<endl;
cout<<" "<<c<<" "<<c<<" "<<endl;
cout<<c<<c<<c<<c<<c<<c<<c<<c<<c<<endl;
}
If you have any doubt then please comment below
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.