Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // *************************
- //HW4prj5.cpp
- //
- //Author: Evan Anderson
- //Created: 9/03/2013
- //*************************
- #include <iostream>
- using namespace std;
- double calcInflationRate(double, double);
- double calcFutureCost(double, double);
- int main() {
- double oldPrice, newPrice, inflationRate, futurePrice; //Define the variables
- char doAgain = 'y';
- while(doAgain == 'y' || doAgain == 'Y') {
- cout << "Enter the price of the item from 1 year ago: ";
- cin >> oldPrice;
- cout << "Enter the current price of the item: ";
- cin >> newPrice;
- inflationRate = calcInflationRate(oldPrice, newPrice);
- futurePrice = calcFutureCost(newPrice, inflationRate);
- cout.setf(ios::fixed);
- cout.setf(ios::showpoint);
- cout.precision(1);
- cout << "\nThe inflation rate was calculated to be " << inflationRate * 100 << "%";
- cout.precision(2);
- cout << "\nThe item will cost $" << futurePrice << " in one year";
- cout << "and $" << calcFutureCost(futurePrice, inflationRate) << " in two years";
- cout << "\n\nWould you like to repeat the calculation? (y or n): ";
- cin >> doAgain;
- }
- return 0;
- }
- double calcInflationRate(double oldPrice, double newPrice) {
- return ((newPrice-oldPrice) / oldPrice);
- }
- double calcFutureCost(double currentPrice, double inflationRate) {
- return (inflationRate * currentPrice) + currentPrice;
- }
Advertisement
Add Comment
Please, Sign In to add comment