2013-11-22 115 views
0

林只是要跳过代码 1)为什么程序继续?

function program() 

choice=input('What is your choice?','s') 
runProgram(choice) 
disp('the program will now end') 

在该函数的不相关部分我只是应该1和5

function runProgram(choice) 

if choice==1 
    loadfile 
elseif..... 
end 

该函数只是确定哪些之间键入一个数字我们将运行的5个子功能。

function loadfile() 

filename=input('Write the name of the file here: ','s') 
loadfile(filename) 

其中loadfile是另一个子函数,但我不需要详细介绍。因为现在我的问题是这样的: 我运行'程序'功能并键入一个数字,但是它只是立即跳到结束消息,程序结束。该程序不应该先通过子功能吗?

回答

2

您正在以字符串形式检索输入。所以比较失败。

只需使用

input('What is your choice?') 

无 'S'

2

choice您的choice变量是一个字符串,但您将其与一个整数(if choice==1)进行比较。您需要将其与字符串进行比较(使用strcmp)或将其转换为数字(使用str2num)。

相关问题