Hello,

I am trying to do the following:

Company needs 200 pens a year. Write a program to gauge the expected cost of an item in a specific number of years. Asks for the cost of the item, numbers of years from now it will be purchased, and the rate of inflation. It outputs the estimated cost of the item after the specific period. Have the user enter the inflation rate as a percentage. Program needs to convert the percentage to a fraction, and should use a loop to estimate the price adjusted for inflation.

What I have right now is this, but I have to use a loop actually..

``````#include <iostream>
#include <cmath>

using namespace std;

int main() {
double CostOfItem;
double NumberYears;
double Inflation;
double Result;

cout << " What's the cost of the item ? : " ;
cin >> CostOfItem ;
cout << " Number of years from now that the item will be purchased: " ;
cin >> NumberYears ;
cout << " Enter the rate of Inflation: " ;
cin >> Inflation ;

// Result = CostOfItem*Inflation^X
Result = pow(CostOfItem * (1 + Inflation/100), NumberYears);

cout << Result << endl;

return 0;
}``````

How do I use a loop here? Can someone tell me in words how the loop is supposed to look like? I think I have to initialize to 0 first. Then somehow implement the equation... no idea.
Help is appreciated!

How do you do it on paper? The parts where you find yourself repeating the same task will fall into a loop in code.

Just solve the equation. But you just do that once with the input that was given to you. Nothing to repeat there.

What do you want to repaet here, the whole program perhaps? There are two forms of loops - While loop and the For loop but i think it would be much simpler if you just googled them, i mean its really a basic thing and its really not hard to find an example.

``````int number_of_repetitions = 10;

for(int i = 0; i < number_of_repetitions; i++)
{
``````int number_of_repetitions = 10;