0

一直在开发一个假设循环并显示 13 次的程序。这是我的代码

 { 
var count; 
var user_Input;
var output_msg;
var cel;
count = 0;

   do 
      { 
        user_Input = get_integer("Temperature conversion","");
        count = count + 1;
        cel = user_Input * 9/5 +32;
        user_Input = user_Input +10;
        output_msg =(string(count) + "Celsius" + string(user_Input) + " = Farenheit " + string(cel));
        show_message(output_msg);
        } 
         until (count == 13)

 }

它的作用是每次我按回车键时显示循环,而不是一次显示所有 13 个,如果我输入 10,例如每次循环它假设从最后一个循环添加 10。

例如。1. 摄氏度 10 = 华氏度(在此处回答)
...... 2. 摄氏度 20 = 华氏度(在此处回答)
......13。Celsuis 130 = Farenheit ""
如果有人可以带我走过并帮助我,那就太好了

4

1 回答 1

1

你需要做的是:

  1. 将对话框移到循环show_message 之外Do,准确地说,是在循环之后。然后,它只会在循环结束时显示,而get_integer对话框当然会等待用户输入一个值。
  2. get_integeraswell 移到循环之外,就在它之前。用户只需输入一次值。如果你把它放在循环中,你会被要求第 13 次输入一个值......
  3. 将结果计算附加到要显示的消息中,其中包含在selfoutput_msg中,最后是换行符。"#"

{
    var count = 0;
    var user_Input;
    var output_msg = "";
    var cel;
    count = 0;

    user_Input = get_integer("Temperature conversion","");
    do
        {
        count = count + 1;
        cel = user_Input * 9 / 5 + 32;
        user_Input = user_Input + 10;
        output_msg = (output_msg + string(count) + ". Celsius" + string(user_Input) + " = Farenheit " + string(cel) + "#");
        }
    until (count == 13)
    show_message(output_msg);
}

为了清楚起见,我已经初始化了一些变量的初始值。

您的问题不是代码问题,而是逻辑问题(换行除外)循环中的所有内容,(Do,While)将在每次迭代时执行。如果您不想执行某些操作,则必须将其移出循环(之前/之后),或使用条件检查。

于 2014-11-09T23:09:46.190 回答