I need help adding on to my C program. it can\'t be C+, has to be regular C. Thi
ID: 3767664 • Letter: I
Question
I need help adding on to my C program. it can't be C+, has to be regular C.
This is what I have so far:
#include <stdio.h>
int main(){
double arr[10];
while(1){
printf("Enter the initial investment: $");
scanf("%lf", &arr[0]);
if(arr[0] > 0 && arr[0] <= 5000) break;
else printf("Amount not in range ");
}
}
read in an integer representing the number of years until retirement. this value represents how many years will pass before you are going to use the money and this is called term. the term should be between 1 and 50.
and then read in an assumed rate return this is a value that will represent how much the investment will increase or decrease each year. This value will be a float value that will be between -15 and 15. in reality this number would change each year but to keep the program simple we are going to assume this value is fixed for the term of the investment
Explanation / Answer
There is no need to use the array or infinite loop. This code can be used to solve your problem.
Code:
#include<stdio.h>
void main()
{
int num_years; //number of years left in retirement
float ror, interest_earned, total, investment;
printf(" Please enter the number of years left to retire ");
scanf("%d",&num_years);
if(num_years<1||num_years>50) //check the values are in the specified range
{
printf("Enter value between 1 and 50");
scanf("%d",&num_years);
}
printf(" Please enter the assumed rate of return on the investment ");
scanf("%f",&ror);
if(ror<-15||ror>15) //check the values are in the specified range
{
printf("Enter value between -15 and 15");
scanf("%f",&ror);
}
printf("Enter the initial investment: $");
scanf("%f", &investment);
interest_earned=(float)(investment*ror*num_years)/100;
printf("The interest on your investment %f is %f ",investment, interest_earned);
total=investment+interest_earned;
printf("You will recieve the amount %f at the time of retirement ",total);
}
I have assumed Simple interest on the investment. If the investment is compounded, replace the statement in bold with the snippet:
interest_earned=(float)investment*(pow((1+ror/100),num_years)-1);
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.