How do I make this program generic: #include <iostream> #include <iomanip> #incl
ID: 3629048 • Letter: H
Question
How do I make this program generic:#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main ()
{
double high_FuelCost;
double high_miles = 400;
double city_FuelCost;
double city_miles = 600;
double MPG = 3.50;
double carInsurance = 100;
double carPayment;
double rate = .01;
double loanAmount = 20000;
double totalExpenses;
//Calculate the highway and city fuel cost.
high_FuelCost = (high_miles/23) * MPG;
city_FuelCost = (city_miles/17) * MPG;
//Calculate the car payment.
carPayment = loanAmount*rate*pow(1+rate,60) / ((pow(1+rate, 60)-1));
//Calculate total car expense.
totalExpenses = (high_FuelCost + city_FuelCost + carInsurance + carPayment);
//Display total car expense.
cout << "Monthly car payment" << setw(23) << carPayment <<endl;
cout << "Monthly fuel cost (city)" << setw(18) << city_FuelCost <<endl;
cout << "Monthly fuel cost (highway)" << setw(15) << high_FuelCost <<endl;
cout << "Monthly insurance cost" << setw(20) << carInsurance << endl;
cout << "Total car expense" << setw(25) << totalExpenses <<endl;
return 0;
}
Explanation / Answer
please rate - thanks
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main ()
{
double high_FuelCost;
double high_miles ;
double city_FuelCost;
double city_miles;
double MPG ;
double carInsurance;
double carPayment;
double rate ;
double loanAmount;
double totalExpenses;
int months;
double cityRate;
double hwyRate;
cout<<"Enter the amount of the car loan: ";
cin>>loanAmount;
cout<<"how many months is the loan for? ";
cin>>months;
cout<<"Enter the yearly interest rate: ";
cin>>rate;
rate/=12.;
rate/=100;
cout<<"what is your monthly insurance? ";
cin>>carInsurance;
cout<<"What is the cars city mileage rating? ";
cin>>cityRate;
cout<<"What is the cars highway mileage rating? ";
cin>>hwyRate;
cout<<"What is the MPG: ";
cin>>MPG;
cout<<"How many miles can you go in the city before needing gas? ";
cin>>city_miles;
cout<<"How many miles can you go on the highway before needing gas? ";
cin>>high_miles;
//Calculate the highway and city fuel cost.
high_FuelCost = (high_miles/hwyRate) * MPG;
city_FuelCost = (city_miles/cityRate) * MPG;
//Calculate the car payment.
carPayment = loanAmount*rate*pow(1+rate,months) / ((pow(1+rate, months)-1));
//Calculate total car expense.
totalExpenses = (high_FuelCost + city_FuelCost + carInsurance + carPayment);
//Display total car expense.
cout << "Monthly car payment" << setw(23) << carPayment <<endl;
cout << "Monthly fuel cost (city)" << setw(18) << city_FuelCost <<endl;
cout << "Monthly fuel cost (highway)" << setw(15) << high_FuelCost <<endl;
cout << "Monthly insurance cost" << setw(20) << carInsurance << endl;
cout << "Total car expense" << setw(25) << totalExpenses <<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.