In: Computer Science
(Using Matlab) and "while" function
1. Write a program that prompts the User for if they would like to enter a real number. If yes, prompt the User for the real number. Continue to do this until the User enters “no” to the first question. After the User enters “no”, display the average of all the numbers entered.
(Using Matlab) and "while" function
2. Write a program that prompts the User for if they would like to enter a real number. If yes, prompt the User for the real number. Continue to do this until the User enters “no” to the first question. After the User enters “no”, display the lowest and the highest number of all the numbers entered.
(Using Matlab) and "while" function
3. Write a program that calculates how many years it will take to accumulate at least $10,000 in an account if the account starts with $500, and at the end of each year you deposit $500, and the current total earns 5% each year. Report on the number of years it will take, and what the total will be.
(Using Matlab) and "while" function
3.2. above to prompt for the ending amount (instead of $10,000.)
(Using Matlab) and "while" function
3.3. above to also prompt the User for the initial starting value for the account.
(Using Matlab) and "while" function
3.4. above to also prompt the User for the amount to deposit each year.
(Using Matlab) and "while" function
3.5. above to also prompt the User for the interest rate.
(Using Matlab) and "while" function
1_code :
output :
raw_code :
%prompting input or output
real = input('Like to enter a real number[[ y /n] ?: ');
numbers = [];
%using while to repeat
while(real =='y' && real ~= 'n')
num = input('Enter number :');
real = input('Would like to enter a real number : ');
numbers = [numbers ,num];
end
%computinig average
if(length(numbers)>0)
average = sum(numbers)/length(numbers)
end
2_code :
output :
raw_code :
%prompting input or output
real = input('Like to enter a real number[[ y /n] ?: ');
numbers = [];
%using while to repeat
while(real =='y' && real ~= 'n')
num = input('Enter number :');
real = input('Would like to enter a real number : ');
numbers = [numbers ,num];
end
%computinig lowest and highest
if(length(numbers)>0)
lowest = min(numbers)
highest = max(numbers)
end
3_code :
output :
raw_code :
%prompting ending ,initial , deposit ,rate
ending = input('Ending amount : ');
initial = input('Starting vlaue : ');
deposit = input('Deposit per year : ');
rate = input('Interest rate : ');
%using loop to count years to accumulate atleast ending
amount
year = 0;
while(ending > initial)
initial = initial + (500*rate/100);
initial = initial + deposit;
year = year +1;
end
%displaying output
fprintf('It will take %d years , for total of
$%f\n',year,initial)
**do comment for queries and rate me up****