Question

In: Computer Science

(Using Matlab) and "while" function 1.   Write a program that prompts the User for if they...

(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

Solutions

Expert Solution

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****


Related Solutions

Exercise 3 – Strings Using a function Write a program that prompts the user to enter...
Exercise 3 – Strings Using a function Write a program that prompts the user to enter two inputs: some text and a word. The program outputs the starting indices of all occurrences of the word in the text. If the word is not found, the program should output “not found”. Example1: Input1: my dog and myself are going to my friend Input2: my Output: 0 11 31 Example 2: Input1: Programming is fun Input 2: my Output: not found
Exercise 4 – Lists and input Using a function Write a program that prompts the user...
Exercise 4 – Lists and input Using a function Write a program that prompts the user to input a sequence of words. The program then displays a list of unique words (words that only occurred once, i.e. no repeated).
Using MATLAB or Octave, Write a script that prompts the user for the coordinates of three...
Using MATLAB or Octave, Write a script that prompts the user for the coordinates of three points A, B, and C, namely (xA, yA), (xB, yB), (xC, yC), forming a triangle, storing each in a variable (for a total of 6 variables). The script should then calculate the centroid G = (xG, yG) using xG = xA+xB+xC 3 and yG = yA+yB+yC 3 , storing each in a variable. Finally, the script should print all four points. Sample output: Enter...
Using MATLAB or Octave, Write a script that prompts the user for a multiplier, storing it...
Using MATLAB or Octave, Write a script that prompts the user for a multiplier, storing it in the variable fMultiplier. The script should them prompt the user for a number, storing it in the variabl fIn. The script should then calculate the product of these two variables, saving the result to another variable fOut, and printing it. The script should then repeat the prompt for fIn, calculation, and output twice more, using the same variable fIn and fOut all three...
Using MATLAB or Octave, Write a script that prompts the user for a minimum and maximum...
Using MATLAB or Octave, Write a script that prompts the user for a minimum and maximum real number, then generates and prints a random number in the requested range. The script should then do the same for an integer range. Sample output: Enter a minimum real value: 0.5 Enter a maximum real value: 30 A random number in the range ( 0.5000, 30.0000 ) is 1.7851 Enter a minimum integer value: -10 Enter a maximum integer value: 20 A random...
Using MATLAB or Octave, use documenting code to Write a script that prompts the user for...
Using MATLAB or Octave, use documenting code to Write a script that prompts the user for a minimum and maximum real number, then generates and prints a random number in the requested range. The script should then do the same for an integer range. Sample output: Enter a minimum real value: 0.5 Enter a maximum real value: 30 A random number in the range ( 0.5000, 30.0000 ) is 1.7851 Enter a minimum integer value: -10 Enter a maximum integer...
Write a program in c++ using only if statements that prompts the user to enter an...
Write a program in c++ using only if statements that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is 1 …., and Saturday is 6) then displays today. Also, prompt the user to enter the number of days after today for a future day and display the future day of the week. The future day can be computed as follows: (today + number of days after today) % 7 Sample run...
1. Write a program that prompts the user for a filename, then reads that file in...
1. Write a program that prompts the user for a filename, then reads that file in and displays the contents backwards, line by line, and character-by character on each line. You can do this with scalars, but an array is much easier to work with. If the original file is: abcdef ghijkl the output will be: lkjihg fedcba Need Help with this be done in only PERL. Please use "reverse"
write this program in C++ Write a program that prompts a user for three characters. The...
write this program in C++ Write a program that prompts a user for three characters. The program must make sure that the input is a number 10 - 100 inclusive. The program must re prompt the user until a correct input is entered. Finally output the largest and the lowest value. Example 1: Input : 10 Input : 20 Input : 30 The largest is 30. The lowest is 10. Example 2: Input : 100 Input : 50 Input :...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for a file name. If the file is not found, an error message is output, and the program terminates. Otherwise, the program prints each token in the file, and the number of times it appeared, in a well formatted manner. To accomplish all this, do the following: - Open the file - the user must be prompted and a file name input. DO NOT hardcode...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT