*2.23 ( Cost of driving ) Write a program that prompts the user to enter the dis
ID: 667438 • Letter: #
Question
*2.23 (Cost of driving) Write a program that prompts the user to enter the distance to
drive, the fuel efficiency of the car in miles per gallon, and the price per gallon,
and displays the cost of the trip. Here is a sample run:
Enter the driving distance: 900.5
Enter miles per gallon: 25.5
Enter price per gallon: 3.55
The cost of driving is $125.36
*3.17 (Game: scissor, rock, paper) Write a program that plays the popular scissor-rockpaper
game. (A scissor can cut a paper, a rock can knock a scissor, and a paper can
wrap a rock.) The program randomly generates a number 0, 1, or 2 representing
scissor, rock, and paper. The program prompts the user to enter a number 0, 1, or
2 and displays a message indicating whether the user or the computer wins, loses,
or draws. Here are sample runs:
scissor (0), rock (1), paper (2): 1
The computer is scissor. You are rock. You won
scissor (0), rock (1), paper (2): 2
The computer is paper. You are paper too. It is a draw
Explanation / Answer
2.23
#include<iostream.h>
int main()
{
float dist,miles,price,cost;
cout<<"Enter the driving distance: ";
cin>>dist;
cout<<endl;
cout<<"Enter miles per gallon: ";
cin>>miles;
cout<<" Enter price per gallon: ";
cin>>price;
if(miles==0)
cout<<"Miles per Gallon Cannot be zero";
else
{
cost=dist*price/miles;
cout<<" The cost of driving is $"<<cost;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.