我需要
外观:
printf("choose option:\n1 - factorial\n2 - fibonacci sequence\n");
scanf("%d", &a);
if (a==1) {
printf("enter a number:\n");
scanf("%d", &x);
return factorial(x);
}
if (a==2) {
printf("enter a number of sequence:\n");
scanf("%d", &y);
return fibonacci(y);
}
问题:第一部分有效,而第二部分无效。 Error: 'exit status 120'
怎么了?
答案 0 :(得分:-3)
/*
For first, variable 'a' should be declared as integer:
*/
int a = 0;
/*
Further, when you read keystrokes, you get ascii code of a character.
Remember:'1' != 1
Your 'if' statement should be different:
*/
if (a == '1') {... } /* note single quote characters around '1' and '2' */
else if (a == '2') {... }
else
{
/* if user press something that is not '1' or '2' */
printf("Wrong choice!\n");
exit(1);
}