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

Create a loop that will prompt the user to enter the fields/properties of an arr

ID: 3633356 • Letter: C

Question

Create a loop that will prompt the user to enter the fields/properties of an array of structure variables for e-books that the user has downloaded one array element at a time. The structure for the e-book should have the fields/properties of author, title, cost, year, plus a field/property of your choice. The loop should continue as long as the user wants to enter more e-books. Assuming the loop runs correctly, write the command(s) necessary to calculate the total amount spent on the books once the structure array has been filled. (This should not be inside the loop).

Explanation / Answer

clear;clc n=true; i = 2; field = input('Field Property of your choice: ','s'); details = {'Author','Title','Cost','Year',field}; while n details(i,1) = {input('Author: ','s')}; details(i,2) = {input('Title: ','s')}; details(i,3) = {input('Cost($): ','s')}; details(i,4) = {input('Year: ','s')}; details(i,5) = {input([field,': '],'s')}; i = i+1; m = input('Do you want to enter another book? (yes/no) ','s'); if strcmp(m,'no') n = false; end end details total_cost = sum(str2double(details(2:end,3))); fprintf('Total cost is $%.2f' ,total_cost);

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