Discuss Basic question im just new in the C/C++ Help forum on Dev Articles. Basic question im just new C/C++ Help forum discussing building and maintaining applications in C/C++. Find out why these languages are the foundation on which other languages are built.

Posts: 2
Time spent in forums: 31 m 49 sec
Reputation Power: 0

General - Basic question im just new

i need this to out put the amount of years the person wants so basiclly if they put 50 year one should be 52.8 year after that should be 52.8 times 1.056 to increase it even more but i cant make it work

#include <iostream>
using namespace std;

int main()
{
double pencils, price, years;
cout << "How many pencils will you be needing?\n";
cin >> pencils;
cout << "How much did that cost you this year.\n";
cin >> price;
cout << "So thats " << (price/pencils) << " each pencil.\n";
cout << "How many years would you like to know the price in advance?\n";
cin >> years;
cout << "With that said your can expect the following prices for the next " << years << " years with 5.6 percent interest.\n ";
double newest;
newest = (price = price*1.056);

while (years > 0)
{
years = years - 1;
cout << newest << "\n";
}
cout << endl;

Posts: 22
Time spent in forums: 9 h 6 m 36 sec
Reputation Power: 0

Would i did was just moved the

Code:

newest = (price = price*1.056);

into the while statement at the bottom so it would execute every time the year increased.

Code:

#include <iostream>
using namespace std;
int main()
{
double pencils, price, years;
cout << "How many pencils will you be needing?\n";
cin >> pencils;
cout << "How much did that cost you this year.\n";
cin >> price;
cout << "So thats " << (price/pencils) << " each pencil.\n";
cout << "How many years would you like to know the price in advance?\n";
cin >> years;
cout << "With that said your can expect the following prices for the next " << years << " years with 5.6 percent interest.\n ";
double newest;
while (years > 0)
{
newest = (price = price*1.056);
years = years - 1;
cout << newest << "\n";
}
cout << endl;
return 0;
}