### While Loop inside a While Loop

Hi everyone,

I've been reading these boards a lot for help while I've been taking an intro to C++ course. But I was hoping I could ask for some help.

I'm creating an Interest Compounding Calculator, and I'm trying to have it execute a while loop inside a while loop.

So far it will give you the interest and the yield from the highest possible interest rate (which the user inputs) and 1. I want it also to repeat this for every year leading upto the number of years the user wants it to run. so eg: if the user wants it to run for 5 years and an interest rate of 5.

I want it to have an output for year 5, and the yields for percents 5, 4, 3, 2, 1
Year 4 and the yields for percents 5, 4, 3, 2, 1
and etc.

I've set up the two while loops but only one of them runs.

Heres my code, thanks for your help!

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798`` ``````#include #include #include using namespace std; void welcome() { cout << " Hello and Welcome to the Compounding Calculator\n" " -----------------------------------------------\n" " Here you can calculate how much your investment will yield\n" " in various scenarios.\n" " Lets Get Started!" << endl; cout << "-------------------------------------------------\n"; cout << " ***Please enter all values numerically***\n" << endl; } void interestCalculation(double& totalValue, double& investmentInt, double& interest, double& length) { while (interest>0) { totalValue = ((investmentInt*(interest/100))+investmentInt)*length; cout << interest << "% = \$" << totalValue << " "; --interest; } cout << endl; } void investEval(double& investInt) { cout << " Please enter the amount of your initial investment: \$"; cin >> investInt; } void interestEval(double& interestRate) { cout << " Please enter the highest amount of interest you approximate you will get: "; cin >> interestRate; } void lengthEval(double& length) { cout << " For how many years do you want to calculate? " ; cin >> length; } int investmentProgram() { double s; welcome(); while(true) { char choice; double investment, interestR, n, value; investEval(investment); interestEval(interestR); lengthEval(n); for (int x=n; x>0; --x) { interestCalculation(value, investment, interestR, n); cout << value; --n; } cout << " Would you like to make another calculation?" << endl; cout << " Enter 'y' for yes and 'n' for no: "; cin >> choice; if (choice == 'y') { continue; } else { break; cout << endl; } } } int main() { investmentProgram(); system("pause"); return 0; }``````
Last edited on
Topic archived. No new replies allowed.