我的 if 语句没有做我需要它做的事情

发布于 2025-01-17 09:32:16 字数 1472 浏览 1 评论 0原文

因此,对于我的数值方法模块,我们要求使用数值方法解决现实世界问题,并通过八度编写脚本,我是我项目的最后一部分,但是它只是不想像我打算这样做一样做?有人可以在这里帮我吗?

代码部分如下: 有争议的代码

F=1;
M=3;
input('has this met your criterion? (F/M): ')

if (F)
 printf('\n'); %Spacer
 printf('__________________________________________________ \n');%Divider
 printf('\n'); %Spacer
 printf('summation of results are as follows:');
 printf('\n'); %Spacer
 printf('___________________________________________\n');%Divider     
 printf('\n'); %Spacer
 printf(__________________________________________\n');%Divider
 printf('\n'); %Spacer
 printf('flows (m3/s)');
 QinPipe1=Q1x2=Di(1,1);
 QinPipe2=Q2x2=Di(2,1);
 QinPipe3=Q3x2=Di(3,1);
 printf('\n'); %Spacer
 printf('\n'); %Spacer
 QinPipe1=Q1x2 
 QinPipe2=Q2x2 
 QinPipe3=Q3x2

  printf("______________________________________\n");
  printf("criterion check(percentage):\n");
  printf('\n'); %Spacer
  printf('\n'); %Spacer
  RelError1=Q1e1=abs(((abs(Q1x)-abs(Q1x2))/abs((Q1x2))))*100; 
  RelError2=Q2e2=abs(((abs(Q2x)-abs(Q2x2))/abs((Q2x2))))*100;
  RelError3=Q3e3=abs(((abs(Q3x)-abs(Q3x2))/abs((Q3x2))))*100; 

  RelError1=Q1e1
  RelError2=Q2e2
  RelError3=Q3e3

else if (M)
 cramerwdntest
 end
endif

我需要做的是,它在运行先前的命令直到运行之前启动这一点一旦用户用f或m回答,它应该打印出脚本运行的最终结果的总和(f),如果没有,则应再次运行以下m文件(m),直到用户最终回答用户回答(f)无论您输入什么字母(m或f),它运行在if语句的第一部分,无论

我试图使用“ yes_or_no”功能,但这似乎不起作用,这两个

都可以帮助我。

so for my Numerical methods module we are requested solving a real world problem using Numerical methods and write a script for it through octave I am the last part of my project but it just doesn't want to do as I intend it to do? can someone perhaps help me here?

The section of code is as follows:
Code in question

F=1;
M=3;
input('has this met your criterion? (F/M): ')

if (F)
 printf('\n'); %Spacer
 printf('__________________________________________________ \n');%Divider
 printf('\n'); %Spacer
 printf('summation of results are as follows:');
 printf('\n'); %Spacer
 printf('___________________________________________\n');%Divider     
 printf('\n'); %Spacer
 printf(__________________________________________\n');%Divider
 printf('\n'); %Spacer
 printf('flows (m3/s)');
 QinPipe1=Q1x2=Di(1,1);
 QinPipe2=Q2x2=Di(2,1);
 QinPipe3=Q3x2=Di(3,1);
 printf('\n'); %Spacer
 printf('\n'); %Spacer
 QinPipe1=Q1x2 
 QinPipe2=Q2x2 
 QinPipe3=Q3x2

  printf("______________________________________\n");
  printf("criterion check(percentage):\n");
  printf('\n'); %Spacer
  printf('\n'); %Spacer
  RelError1=Q1e1=abs(((abs(Q1x)-abs(Q1x2))/abs((Q1x2))))*100; 
  RelError2=Q2e2=abs(((abs(Q2x)-abs(Q2x2))/abs((Q2x2))))*100;
  RelError3=Q3e3=abs(((abs(Q3x)-abs(Q3x2))/abs((Q3x2))))*100; 

  RelError1=Q1e1
  RelError2=Q2e2
  RelError3=Q3e3

else if (M)
 cramerwdntest
 end
endif

What I need it to do is that after it has run the previous commands up until this point once the user answers with either F or M it should either print out the summation (F) of the final results from the script run earlier and if not it should run the following m file (M) again until the user eventually answers with an (F) instead no matter what letter you enter (M or F) it runs the first part of the if statement regardless

I attempted to use the "yes_or_no" function but that seemed to not work either

Could someone please help me on this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明明#如月 2025-01-24 09:32:16

F和M表示什么,为什么将它们设置为1和3?

这里有很多要改进的地方,但是要回答您的问题:

F=1;
M=3;
in = input('has this met your criterion? (F/M): ','s')

if in == 'F'
  ...

's'用于指定输入字符串(字符)。您必须将输入存储在变量中。我在中称其为,但是您应该选择一个在脚本中与其目的匹配的变量名称。

您必须将输入与字符f输入一个数字而不是字符串进行比较。


新答案:

in = input('Is this OK? (Y / N)', 's');
while in ~= 'Y' && in ~= 'N'
    in = input('Please answer with "Y" or "N". Is this OK?', 's');
end

if in == 'Y'
   ... 

    

What do F and M represent, and why do you set them to 1 and 3?

There's a lot to improve here, but to answer your question:

F=1;
M=3;
in = input('has this met your criterion? (F/M): ','s')

if in == 'F'
  ...

's' is used to specify that you input a string (character). You must store the input in a variable. I've called it in but you should choose a variable name that matches its purpose in your script.

You must compare the input to the character F, or input a number instead of a string.


New answer:

in = input('Is this OK? (Y / N)', 's');
while in ~= 'Y' && in ~= 'N'
    in = input('Please answer with "Y" or "N". Is this OK?', 's');
end

if in == 'Y'
   ... 

    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文