[英]Why does it never enter in a for loop?
This is my first time asking a question on stack overflow. 这是我第一次问堆栈溢出问题。 My switch statement which switched on an enumerated type inputted by the user is only working for case: QUIT .
我的switch语句打开了用户输入的枚举类型,仅在以下情况下有效:QUIT。 Here is my code:
这是我的代码:
int get_function(menu_t get_input)
{
int i;
double rad, result;
switch ( get_input )
{
case Sin:
i = 0;
for (i = 0; i > loop_limit; i += step_size)
{
rad = PI * (i /180);
result = sin(rad);
printf("\tsin(%d) = %.4lf\n", i, result);
printf("\n");
}
break;
case Cos:
for(i = 0; i > loop_limit; i += step_size)
{
rad = PI * (i /180);
result = cos(rad);
printf("\tcos(%d) = %.4lf\n", i, result);
printf("\n");
}
break;
case Tan:
for(i = 0; i > loop_limit; i += step_size)
{
if(i <= 75)
{
rad = PI * (i /180);
result = tan(rad);
printf("\ttan(%d) = %.4lf\n", i, result);
printf("\n");
}
else
{
printf("\ttan(%d) is UNDEFINED", i);
}
}
break;
case QUIT:
printf("You chose QUIT. Thank you, come again!\n");
break;
}
return(0);
}
As you can see I'm using for loops inside the cases that aren't executing... is this the problem? 如您所见,我在没有执行的情况下使用for循环...这是问题吗? Thanks to anyone who can help me with this...
感谢任何可以帮助我的人...
There is a typo in your for loops. for循环中有错别字。 With this writing :
撰写本文时:
for(i = 0; i > loop_limit; i += step_size)
You will set i = 0 and ask the work being done as long as i > loop_limit ... so, never. 只要i> loop_limit ...,就可以设置i = 0并要求完成工作。
The correct writing is : 正确的文字是:
for(i = 0; i <= loop_limit; i += step_size)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.