Probably doing something stupid..
question = input('Enter a question about volume: ','s');checkExit = 'exit';exit = strfind(question,checkExit);while(length(exit)==0)ifCube = 'cube';cube = strfind(question,ifCube);if(length(cube)==0) display('you did not specify the shape'); %the word cube isn't in the sentence
else posH = 'height of'; Index = strfind(question, posH); height = sscanf(question(Index(1) + length(posH):end), '%d', 1); volCube = height * height * heightendifCyl = 'cylinder';cylinder = strfind(question,ifCyl);if(length(cylinder)==0) %the word cylinder isn't in the sentence
else posH = 'height of'; Index = strfind(question, posH); height = sscanf(question(Index(1) + length(posH):end), '%d', 1); posR = 'radius of'; Index2 = strfind(question, posR); radius = sscanf(question(Index2(1) + length(posR):end), '%d', 1); volCyl = 2*pi*radius*height endifCone = 'cone';cone = strfind(question,ifCone);if(length(cone)==0) %the word cone is not in the sentence
else posH = 'height of'; Index = strfind(question, posH); height = sscanf(question(Index(1) + length(posH):end), '%d', 1); posR = 'radius of'; Index2 = strfind(question, posR); radius = sscanf(question(Index2(1) + length(posR):end), '%d', 1); volCone = pi*((radius)^2)*(height/3)endifSphere = 'sphere';sphere = strfind(question,ifSphere);if(length(sphere)==0) %the word sphere is not in the sentence
else posR = 'radius of'; Index2 = strfind(question, posR); radius = sscanf(question(Index2(1) + length(posR):end), '%d', 1); volSphere = (4/3)*pi*(radius)^3end end
I want to keep asking the user to enter a question about volume until the say 'exit'. However, I don't know how to keep myself from getting stuck in while loop, if I set exit = 1 in each of the if statements it breaks the out of the while loop obviously but I want to continuously ask the user questions. I'm stumped, and a point in the right direction would be very helpful.
Thank you.
Best Answer