为什么我的“ do-while”语句只能相反地起作用?

时间:2019-07-02 23:00:59

标签: c do-while cs50

我正在尝试为CS50分配一个Mario副本,并且我需要使用do-while语句来完成它。我希望输入在1到8之间,所以我做了while语句,像这样:[resourceId('Microsoft.Network/loadBalancers/frontendIpConfigurations', variables('loadBalancerName'), concat(variables('subnet1name'), '-FrontEnd'))] 。这似乎不起作用,因为当我输入9或0时,它将像往常一样继续运行该程序。当我将符号更改为 { "message": "accurate", "cod": "200", "count": 5, "list": [ { "id": 2643743, "name": "London", "coord": { "lat": 51.5073, "lon": -0.1277 }, "main": { "temp": 15.91, "pressure": 1025, "humidity": 93, "temp_min": 13.33, "temp_max": 18.33 }, "dt": 1562101758, "wind": { "speed": 2.6, "deg": 60 }, "sys": { "country": "GB" }, "rain": null, "snow": null, "clouds": { "all": 0 }, "weather": [ { "id": 800, "main": "Clear", "description": "clear sky", "icon": "01n" } ] }, { "id": 6058560, "name": "London", "coord": { "lat": 42.9886, "lon": -81.2467 }, "main": { "temp": 26.13, "pressure": 1011, "humidity": 69, "temp_min": 22.22, "temp_max": 28.33 }, "dt": 1562101768, "wind": { "speed": 4.6, "deg": 270 }, "sys": { "country": "CA" }, "rain": null, "snow": null, "clouds": { "all": 75 }, "weather": [ { "id": 803, "main": "Clouds", "description": "broken clouds", "icon": "04d" } ] }, { "id": 4298960, "name": "London", "coord": { "lat": 37.129, "lon": -84.0833 }, "main": { "temp": 26.08, "pressure": 1017, "humidity": 100, "temp_min": 22, "temp_max": 28.89 }, "dt": 1562101777, "wind": { "speed": 2.84, "deg": 283.644 }, "sys": { "country": "US" }, "rain": null, "snow": null, "clouds": { "all": 1 }, "weather": [ { "id": 211, "main": "Thunderstorm", "description": "thunderstorm", "icon": "11d" } ] }, { "id": 4517009, "name": "London", "coord": { "lat": 39.8864, "lon": -83.4483 }, "main": { "temp": 32.92, "pressure": 1013, "humidity": 41, "temp_min": 27.78, "temp_max": 35 }, "dt": 1562101777, "wind": { "speed": 5.7, "deg": 260 }, "sys": { "country": "US" }, "rain": null, "snow": null, "clouds": { "all": 1 }, "weather": [ { "id": 211, "main": "Thunderstorm", "description": "thunderstorm", "icon": "11d" } ] }, { "id": 4119617, "name": "London", "coord": { "lat": 35.329, "lon": -93.253 }, "main": { "temp": 29.93, "pressure": 1015, "humidity": 70, "temp_min": 28.89, "temp_max": 31.11 }, "dt": 1562101885, "wind": { "speed": 3.1, "deg": 250 }, "sys": { "country": "US" }, "rain": null, "snow": null, "clouds": { "all": 1 }, "weather": [ { "id": 800, "main": "Clear", "description": "clear sky", "icon": "01d" } ] } ] } 时,它允许我输入大于8且小于1的数字,但是当我输入介于8和1之间的数字时,它不接受并告诉我输入新的数字。为什么只有当我逆时它才起作用?

我尝试过切换标志,切换顺序和切换括号,但仍然无法正常工作。

这是我的代码:

<p id="name"></p>
<p id="temp"></p>
<p id="temp_min"></p>
<p id="temp_max"></p>

<button>Get Weather</button>
<script>
    $(document).ready(function () {
        $("button").click(function () {

            $.get("http://api.openweathermap.org/data/2.5/find?q=London&appid=b9acdc9c9950140623607d0a90eb40b7&units=metric",
                function (response) {
                    // response
                    $("#name").text(response.list.name);
                    //  $("#temp").text(response.main.temp);
                    //  $("#temp_min").text(response.main.temp_min);
                    // $("#temp_max").text(response.main.temp_max);
                    console.log(response);


                });
        });
    });

</script>

我希望它拒绝高于8或低于1的任何答案,但它仍然会接受。

1 个答案:

答案 0 :(得分:1)

如注释中所述,必须编写条件,以便在输入为<1 > 8而不是“ and”时运行循环:值不能同时为<1和> 8。

C中的“或”为||

否定逻辑条件需要同时反转其 operand 及其 operators 的原因可以通过思考或填写{{3 }},但它也已在truth table中正式化。简短地,

  • a && b的取反是(!a) || (!b)
  • a || b的取反是(!a) && (!b)