0
votes

In the code, the "createbook" and "displaybook" are functions Ive created and I know that these work and are not the issue. If someone could help me I would really appreciate it. If you need more information, just leave a comment and Ill get back to you

Books = [];

Choice = input('What would you like to do: ','s'); 

while (Choice)

   if Choice == 'add book'

      Title = input('Enter the title: ','s');
      Author = input('Enter the author: ','s');
      Pages = input('Enter the number of pages: ');

      New = createbook(Title, Author, Pages);

      displaybook(New);

      fprintf('%s has been added to the library\n',New)

      Books = [Books New];

   elseif Choice == 'quit'

      disp('PROGRAM END')

      return;  

   end

   Choice = input('What would you like to do: ','s'); 

end
1
use strcmp for comparing strings - and learn how to use debugger - matlabgui
Welcome to the site! Check out the tour and the "how to ask" page for more about asking questions that will attract quality answers. Please edit your question to include at least the following: the specific error message; the line number on which the error is reported; the Matlab or Octave version you are using; and what the dimensions of some of the relevant matrices are. Thanks, and good luck! - cxw
Also, see some of the "Related" questions on the right --- maybe one of those will help. --------> - cxw

1 Answers

0
votes

Use strcmp instead of (==). The reason is that when you write in Matlab the statement if ('string1' == 'string2'), it returns a boolean vector, which checks for each index i if (str1[i] == str2[i]). If the two strings have different lengths it will throw an exception