Question

In: Computer Science

Matlab question: By using while loop to solve, Sum up bottles until you are over 75....

Matlab question:

By using while loop to solve, Sum up bottles until you are over 75. How many days/loops are needed? Print out cups on the shelf and total until you reach at least 75.

Finish the code below,

least_num_Cups = randi([75, 300], 1,1);

while

totalCups = % Change this code to reflect change in totalCups

fprintf('%0.0f cups of tea on the shelf, total %0.0f\n',);

k = ; % Change code to update k

end

k_complete = ; % Change variable to determine k value when totalCups requirement is met

Make the output looks like:

1 cups of tea on the shelf, total 1

2 cups of tea on the shelf, total 3

3 cups of tea on the shelf, total 6

4 cups of tea on the shelf, total 10

5 cups of tea on the shelf, total 15

6 cups of tea on the shelf, total 21

7 cups of tea on the shelf, total 28

8 cups of tea on the shelf, total 36

9 cups of tea on the shelf, total 45

10 cups of tea on the shelf, total 55

11 cups of tea on the shelf, total 66

12 cups of tea on the shelf, total 78

Total number of cups is: 78 after 12 loops

Solutions

Expert Solution

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!
===========================================================================

least_num_Cups = randi([75, 300], 1,1);

k = 1;
days = 0;

totalCups = 0;

while totalCups<75

totalCups = totalCups+k;% Change this code to reflect change in totalCups
days+=1;


fprintf('%0.0f cups of tea on the shelf, total %0.0f\n',days,totalCups);

k = k+1; % Change code to update k


end
k_complete = totalCups; % Change variable to determine k value when totalCups requirement is met

printf("Total number of cups is: %d, after %d loops\n",k_complete,days);


Related Solutions

Can you rewrite this MATLAB code using a for loop instead of a while loop? %formatting...
Can you rewrite this MATLAB code using a for loop instead of a while loop? %formatting clc, clear, format compact; %define variables k=1; b=-2; x=-1; y=-2; %while loop initialization for k <= 3 disp([num2str(k), ' ',num2str(b),' ',num2str(x),' ',num2str(y),]); y = x^2 -3; if y< b b = y; end x = x+1; k = k+1; end
Write a Java program using using WHILE loop to find the sum of all integers between...
Write a Java program using using WHILE loop to find the sum of all integers between 200 to 250 which are divisible by 7. Sample Output: Numbers between 200 and 250, divisible by 7: 203 210 217 224 231 238 245 The sum is: 1568
PL/SQL Write a PL/SQL block, using a While Loop, to calculate and print the sum of...
PL/SQL Write a PL/SQL block, using a While Loop, to calculate and print the sum of the odd integers from 10 to 120 inclusive. (Hint: 11 + 13 + 15 + . . . + 97 + 99)
solve any question about fourier series by using MATLAB
solve any question about fourier series by using MATLAB
define a matlab question and solve with matlab codes (rlc circuts)
define a matlab question and solve with matlab codes (rlc circuts)
The following code must be written using matlab How to loop through a vector in matlab...
The following code must be written using matlab How to loop through a vector in matlab and assigning a value to every 4th entry. The vector could be of any length. Thanks
Matlab project: Solve using Matlab three problems: One using the combination formula One using the permutation...
Matlab project: Solve using Matlab three problems: One using the combination formula One using the permutation of n objects formula One using the permutation of r objects out of n objects You can pick these problems from the textbook or you can make up your own questions.
Question 1 Using MATLAB solve the following system of linear simultaneous equations 3x + 2y -...
Question 1 Using MATLAB solve the following system of linear simultaneous equations 3x + 2y - z = 10........... [1] -x + 3y + 2z = 5........... [2] x - y - z = -1 .................[3] s + 2t - 3u + 4v = 12........... [1] 2s + 2t - 2u + 3v = 10......... [2] t + u = -1............................ [3] s - t + u - 2v = -4................ [4]
The following code must be written using matlab and must be using a for-loop. NOTE! Write...
The following code must be written using matlab and must be using a for-loop. NOTE! Write a computer program that assigns random integers for each entry and generates a row vector. Different random integers should be drawn from different intervals for position 1, position 2, position3 and position 4 of the array. After these first 4 positions are drawn. The whole thing should start over where position5 drawn from same interval as positions 1, position6 drawn from same interval as...
The following code must be written using matlab and must be using a for-loop. NOTE! Write...
The following code must be written using matlab and must be using a for-loop. NOTE! Write a computer program that assigns random integers for each entry and generates a row vector. Different random integers should be drawn from different intervals in chunks of 4 , that is chunk1-chunk2-chunk3-chunk4 The parameters for specifying the lintervals by which the random numbers should be drawn should be able to change and be hardcoded in the script, however, be hardcoded in the script.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT