Hello people. I love this site. I needed help with my homework and someone came through, even gave me a link for some tutorials from this site which, btw helped me ALLOOOOTOTTT!!!!!!!!!!!!!!!!!!
But I am stuck on the last part of my homework. So this is my homework:
:::::::Write a program that will ask the user to input:
The number of gallons in the tank
The fuel efficiency in miles per gallon
The price of gas per gallon
Then it will print out how far the car can go with the gas in the tank and print the cost per 100 miles.::::::::::::::::::::
and this is what I have so far:::::::::::
#include <iostream>
int main()
{
double numGallons;
double mpg;
double price;
std::cout<<"Enter the number of gallons in the tank: ";
std::cin>>numGallons;
std::cout<<"Enter you vehicle's fuel efficiency in miles per gallon: ";
std::cin>>mpg;
std::cout<<"Enter the price per gallon of gas: $";
std::cin>>price;
}
So I just need help with the last part, where it calculates i supposed. PLEASE please help. Thank you in advance.
Thanks for the response. Ill figure it out i suppose. Is there a tutorial on this subject because is kicking my butt hard. And I just stare at it and cant figure it out
There is an entire tutorial on the basics of C++ on this website.
I guess I will be nice and write the computational code, because I'm nice and all that. :)
1 2 3 4 5
double dist, cpm, cfdist;
dist=mpg*numGallons;
cpm=mpg/price;
cfdist=cpm*100;
//double JamesBond + short Goldfinger = char redBricksOfGold; Don't include that.
we can solve your problem by looking at the problem from the object oriented view point , i think if you look at it from this view point you may get bonus marks ,
explaining :
you can look at the car as an object ,and this object is from the class cars
very simple your name is "xcure " for example, you comes from the class human , the class cars can be characterised by two things :
1) variables , 2) operation done on this variables
for example : the car speed is one of the class "cars" variable we can make operation on this variable speed the car , or slow the car
so here we have operations done on the variable " car speed " ,which are "increase the speed of the car" , or "slow the car speed ".
for your home work :
you own a car say BMW , BMW is from the class cars which MERCEDES belong to also , but your expensive car have it's characteristics which is not found in hyundai my car .
so , now we define your car variables :
1) number of gallons in the tank .
think , if there is any other variable related to your car ? ,the answer is "yes " why "yes" ? what about the fuel efficiency in miles per galon , it is related to your expensive car and differ from car to car so it is a characteristic for your car so it is a second variable
2)fuel efficiency in miles per galon.
3) the distance cut by the car.
and about the price of gas per gallon it is not related to the car by any mean so it is not a chatacteristic of the car it is just a an operation done on your car variable " the no of gallons in the tank " .
after this we determine the type of each variable
1) is double . why ?
2)is double.
3)is double .
then we define the operation that is done on your car variables
which will be :
1) read the no of gallons in your car . // read_galons()
2) read the efficency . // read_efficiency()
3) how far the car can go . // far_go()
4) calculating the cost per 100 miles . // calc_cost(double price )
5) printing the cost per 100 miles . // print_cost()
6) printing the distance . //print_distance()
but i want to explain something here , the third operation will take the price
of the gas per gallon as a passed parameter to the fuction calc_cost() ,
think why ?
after this we have to make a definition of this operations .
and then determine the return type of each operation .
and that's all .
for example read_galons() , let it be of type bool ,
and read_efficiency let it be of type bool also , far_go of type double ,
calc_cost(double price ) of type double , print_cost() of type void will not return any thing also print_distance()b of type void .
you see it is so easy .
then you have to define each operation what it will do ?
so make a defintion of each operatrion
go and think
experirence is the best teacher in the world