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 . 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? Thanks to anyone who can help me with this...
There is a typo in your for loops. 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.
The correct writing is :
for(i = 0; i <= loop_limit; i += step_size)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.