我的任务是使用两种不同的循环(For,While,While While)。任务是要求用户输入一个介于1到10之间的数字,然后该程序将从0计数到用户数量。此外,程序必须能够显示错误消息,并要求用户在1至10之外输入一个数字时再次输入一个数字。错误消息的代码部分和提示再次输入数字工作得很好。但是,当我在范围内输入一个数字时,它不会执行任何操作或从0到无限次数的计数,并且不会停止循环计数。请帮忙!您而为什么我的程序不会停止循环?
#include <stdio.h>
int main(void)
{
//Variables
int num;
int zero;
//Explains to the user what the program will do
printf("This program will count from 0 to a number you pick.\n\n");
//Asks the user to input a value
printf("Please enter a number (between 1 and 10): \n");
scanf("%d", &num);
//If the correct range was selected by the user
while (num >= 1 && num <= 10)
{
for (zero = 0; zero <= num; zero++)
{
printf("%d...", zero);
}
}
//If a value outside of the accepted range is entered
while (num < 1 || num > 10)
{
printf("I'm sorry, that is incorrect.\n");
printf("Please enter a number (between 1 and 10): \n");
scanf("%d", &num);
}
printf("\n\n\n");
return 0;
}
你需要证明你的程序。 – lurker
欢迎来到StackOverflow。基于对问题的模糊描述,我们无法帮助您找到我们看不到的代码。请访问[SSCCE](http://sscce.org),然后回到这里并编辑您的问题,并提供您的**相关**代码的SSCCE(不是大代码转储),明确说明该问题,并根据该代码提出具体问题,也许我们可以帮助您解决问题。 –
提供一些示例代码。它不需要工作,但显示努力。您将需要声明几个变量,打印提示,接受输入,将其转换为数字,然后在该数字上循环。刺伤它。 – ChuckCottrill