Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem: Complete a program that lets users estimate investment returns. The use

ID: 3655708 • Letter: P

Question

Problem:
Complete a program that lets users estimate investment returns. The users would enter an investment amount, an annual compounded interest rate, and period information (i.e. start year and end year) and get the investment return value at the end. Design the program so that the users can try as many time as they want, i.e. they can try different investment conditions to estimate their returns in one run of the program. Provide good user prompts but don't forget to do data validation. For example, all input should be positive numbers and end year should be later than the start year. Be sure to provide meaningful and organized output as well.

this is the code i have made, but some of the end results are correct, and others are in scientific notation.
could anyone shed light on what I am doing wrong? thanks!

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main ()
{

double P, //Principle amount
r, //interest rate
StartYear, //start of period
EndYear, //end of period
again; //should loop iterate more than once


//Instructions
cout << "Instructions: ";
cout << "This program will help you estimate your investment returns. ";
cout << "Please ONLY input numbers (ie 5% as .05, and $1000 as 1000) ";


do {

//Get investment amount
cout << "Enter the investment amount: ";
cin >> P ;

//Validate investment amount
for ( ; P <= 0 ; )
{
cout << "Please enter an amount greater than zero: ";
cin >> P ;
}
//-------------------------------------------------------------------------------------------

//Get investment rate
cout << "Enter the the annual compounded interest rate: ";
cin >> r;

//validate investment rate
while ( (r > 1) || (r < 0) )
{
cout << "Please enter a valid rate. (ie 1% as .01, and 100% as 1): ";
cin >> r;

}
//-------------------------------------------------------------------------------------------

//Get starting year
cout << "Please enter the START year: ";
cin >> StartYear;

//validate start year
for ( ; StartYear < 1900 ; )
{
cout << "Please enter a realistic starting year: ";
cin >> StartYear;
}
//-------------------------------------------------------------------------------------------

//Get ending year
cout << "Please enter the END year: ";
cin >> EndYear;

//validate end year
for ( ; EndYear <= StartYear ; )
{
cout << "Please enter a valid end year: ";
cin >> EndYear;
}
//-------------------------------------------------------------------------------------------

//compound interest rate formula: A = P( 1 + (r/n)) ^ nt
//declare more variables
double n = 1,
t = (EndYear - StartYear), //period span
A, //investment return
result; // includes everything without ^nt
//Calculate
result = ( P * (1 + (r/n)) );
A = pow(result, (n * t));

//Display investment return
cout << " You investment return is: $" << fixed << showpoint << setprecision(2) << A << ". ";


//-------------------------------------------------------------------------------------------

//Asks if you want to do program again
cout << " Would you like to enter new data? ";
cout << "Enter "1" for YES, or "2" for NO: ";
cin >> again;
cout << " ";
}

while ((again < 1)||(again > 2));
{
if (again == 2)
cout << " Thanks for using my program. Have a good day." << endl;
if ( again == 1)
return main();

}
//-------------------------------------------------------------------------------------------


return 0;
}

Explanation / Answer

if your compiler starts using scientific notation, it means that your number was getting too big/small. It does that to keep within its precision. doubles go to ~15 digits. .... while ((again < 1)||(again > 2));
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote