# Ch4_5 - /************************************************/

This preview shows page 1. Sign up to view the full content.

#include <iostream.h> #include <conio.h> /************************************************** Name: Hung Truong Program: Instructor: Mr. Barkeshli Purpose: Chapter 4_5: Inflation rate over years Input: Prices one year ago and today Output: Inflation rate, estimated price next year **************************************************/ bool t=true; char c; double last, now,rt; double irate(double previous, double today); //Calculate the inflation rate by price of last year and today double eprice(double price,double rate, int year); //Estimate the price by inflation rate in years main() { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(3); while (t==true) { cout<<"Enter price of hot dog at PCC last year: ";cin>>last; cout<<"Enter price of hot dog at PCC today: ";cin>>now;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: /************************************************/ cout&lt;&lt;&quot;Inflation Rate: &quot;&lt;&lt;100*irate(last,now)&lt;&lt;endl; rt=irate(last,now); cout&lt;&lt;&quot;Estimated price of hot dog at PCC next year: &quot;&lt;&lt; eprice(now,rt,1)&lt;&lt;endl; cout&lt;&lt;&quot;Estimated price of hot dog at PCC next 2 year: &quot;&lt;&lt; eprice(now,rt,2)&lt;&lt;endl; /************************************************/ cout&lt;&lt;&quot;You want to do it again(Y/N)? &quot;;cin&gt;&gt;c; t=(c=='Y')|(c=='y'); } } double irate(double previous, double today) { double temp; temp=(today-previous)/previous; return temp; } double eprice(double price, double rate, int year) { double temp=price; int i; for (i=1;i&lt;=year;i++) temp=temp*(1+rate); return temp; }...
View Full Document

## This note was uploaded on 03/20/2011 for the course CS 2 taught by Professor Barkeshli during the Spring '11 term at Pasadena City College.

Ask a homework question - tutors are online