I'm having trouble with the second part of my programming projects. For the first one I believe I did everything correctly except I don't know what a globally defined constant is. Can somebody show me how to do this and please check if I did it correctly based on the problem. Any help/advice is greatly appreciated
A liter is 0.264179 gallons. Write a program that will read in the number of liters of gasoline consumed by the user's car and the number of miles per gallon the car delivered. Your program should allow the user to repeat this calculation as often as the user wishes. Define a function to compute the number of miles per gallon. Your program should use a globally defined constant for the number of liters per gallon.
After doing this...
Modify your program so that it will take input data for two cars and output the number of miles per gallon delivered by each car. Your program will also announce which car has the best fuel efficiency (highest number of miles per gallon).
Code:
#include <iostream>
using namespace std;
int main(void)
{
const double GALLONS_PER_LITER = 0.264179;
int liters = 0;
double distance = 0.0;
double mpg = 0.0;
do
{
cout << "Please input how many liters of gasoline is in your vehicle: ";
cin >> liters;
cout << "Please input the distance in miles you traveled in your vehicle: ";
cin >> distance;
mpg = distance / (liters * GALLONS_PER_LITER);
cout << "Your vehicle's MPG is: " << mpg << endl;
}while(liters >-1);
return 0;
}
I'm totally lost on the second part of this program as well.
Write a program to gauge the rate of inflation for the past year. The program ask for the price of an item(Such as a hot dog or a one carat diamond) both one year ago and today. It estimates the inflation rate as the difference in price divided by the year ago price. Your program should allow the user to repeat this calculation as often as the user wishes. Define a function to compute the rate of inflation. The inflation should be a value of type double giving the rate as a percent, for example 5.3 for 5.3%.
Enhance your program from the previous programming project by having it also print out the estimated price of the item in one and in two years from the time of the calculation. The increase in cost over one year is estimated as the inflation rate times the price at the start of the year. Define a second function to determine the estimated cost of an item in one year, given the current price of the item and the inflation rate as arguments.
Code:
#include <iostream>
using namespace std;
int main()
{
double rate;
double price_last_year, price_this_year;
while(price_last_year != 0.0){
cout << "Enter price of item from last year: " << endl;
cout << "Enter 0.0 to quit" << endl;
cin >> price_last_year;
if(price_last_year == 0.0)
exit(1);
cout << "Enter price of item for this year: ";
cin >> price_this_year;
rate = ((price_this_year) - (price_last_year))/price_last_year;
cout << "Rate of inflation is\n" << rate << "%" << endl;
}
return 0;
}