他のすべては正常に機能しますが、減算または除算の部分に進んでみてください(演習の一部は、負の答えがある減算の質問、または0による除算または答えが1未満の除算の質問をしないことです)。最初は機能しますが、次に別の質問に答えてみてください。初期化関数に含まれていないこの複雑な質問を出すので、答えてみましたが、それでも間違った答えから正しいものを検出できます。次に、この32-9または32/9を出力します(余りが必要で、質問が複雑すぎるため、除算部分に答えることができませんでした)。あなたが正しい答えを出した後、別の減算/除算の質問に答えてみてください、そしてそれはクラッシュしてこのエラーを出しますプロセスは-1073741819を返しました私のコードの何が問題になっていますか?よろしくお願いします! ところで、除算と減算を制限することになっているコードの部分にコメントを付けました
/* Arithmetic Quiz Practice Program */
#include <stdio.h>
#include <stdlib.h>
int numbers[10];
int clear(void);
int initialize(void);
int additionquiz(void);
int subtractionquiz(void);
int multiplicationquiz(void);
int divisionquiz(void);
/* Main Menu */
int main()
{
while(1==1)
{
int choice;
initialize();
printf("Arithmetic Quiz 4/10/2012");
printf("\n1 - Addition Quiz\n2 - Subtraction Quiz\n3 - Multiplication Quiz\n4 - Division Quiz\n5 - Exit Program\n");
scanf("%d",&choice);
if(choice==1)
{
clear();
additionquiz();
}
else if(choice==2)
{
clear();
subtractionquiz();
}
else if(choice==3)
{
clear();
multiplicationquiz();
}
else if(choice==4)
{
clear();
divisionquiz();
}
else if(choice==5)
{
exit(EXIT_SUCCESS);
}
else
{
printf("\n%cPlease input a valid option\n",7);
main();
}
}
return 0;
}
/* Function for clearing the page */
int clear()
{
int i;
for(i=0;i<25;i++)
{
printf("\n");
}
return 0;
}
/* Function for initializing the Array */
int initialize()
{
numbers[0]=9;
numbers[1]=5;
numbers[2]=1;
numbers[3]=4;
numbers[4]=7;
numbers[5]=8;
numbers[6]=3;
numbers[7]=6;
numbers[8]=2;
numbers[9]=0;
return 0;
}
/* Function for the Addition Quiz */
int additionquiz()
{
/* Randomizing the question in addition quiz */
int a,b,diff,ans,again;
a=0;
diff=1;
b=a+diff;
if(a>9)
{
a=0;
diff++;
}
if(diff>9);
{
diff=0;
}
if(b>9);
{
b=0;
}
/* Main part of the addition quiz */
while(1==1)
{
printf("\n%d + %d = ",numbers[a],numbers[b]);
scanf("%d",&ans);
if(ans==numbers[a]+numbers[b])
{
printf("\nYour answer is CORRECT!!!\n");
a++;
}
else
{
printf("\nYour answer is WRONG!!!\n");
additionquiz();
}
/* The loop for addition quiz" */
while(1==1)
{
printf("\n1 - Answer another addition question\n2 - Go back to main menu\n3 - Exit program\n");
scanf("%d",&again);
if(again==1)
{
clear();
break;
}
else if(again==2)
{
clear();
main();
}
else if(again==3)
{
exit(EXIT_SUCCESS);
}
else
{
printf("%cPlease input a valid option.\n",7);
continue;
}
}
continue;
}
}
/* Function for the subtraction quiz */
int subtractionquiz()
{
/* Randomizing the question in subtraction quiz */
int a,b,diff,ans,again;
a=0;
diff=1;
if(a>9)
{
a=0;
diff++;
}
if(diff>9);
{
diff=0;
}
b=a+diff;
if(b>9);
{
b=0;
}
/* Main part of the subtraction quiz */
while(1==1)
{
/* Not allowing questions with negative answer */
while(numbers[a]<numbers[b])
{
a++;
}
printf("\n%d - %d = ",numbers[a],numbers[b]);
scanf("%d",&ans);
if(ans==numbers[a]-numbers[b])
{
printf("\nYour answer is CORRECT!!!\n");
a++;
}
else
{
printf("\nYour answer is WRONG!!!\n");
subtractionquiz();
}
/* Loop for the subtraction quiz */
while(1==1)
{
printf("\n1 - Answer another subtraction question\n2 - Go back to main menu\n3 - Exit program\n");
scanf("%d",&again);
if(again==1)
{
clear();
break;
}
else if(again==2)
{
clear();
main();
}
else if(again==3)
{
exit(EXIT_SUCCESS);
}
else
{
printf("%cPlease input a valid option.\n",7);
continue;
}
}
continue;
}
}
/* Function for multiplication quiz */
int multiplicationquiz()
{
/* Randomizing the multiplication quiz */
int a,b,diff,ans,again;
a=0;
diff=1;
b=a+diff;
if(a>9)
{
a=0;
diff++;
}
if(diff>9);
{
diff=0;
}
if(b>9);
{
b=0;
}
/* Main part of the multiplication quiz */
while(1==1)
{
printf("\n%d x %d = ",numbers[a],numbers[b]);
scanf("%d",&ans);
if(ans==numbers[a]*numbers[b])
{
printf("\nYour answer is CORRECT!!!\n");
a++;
}
else
{
printf("\nYour answer is WRONG!!!\n");
clear();
multiplicationquiz();
}
/* Loop for multiplication quiz */
while(1==1)
{
printf("\n1 - Answer another multiplication question\n2 - Go back to main menu\n3 - Exit program\n");
scanf("%d",&again);
if(again==1)
{
clear();
break;
}
else if(again==2)
{
clear();
main();
}
else if(again==3)
{
exit(EXIT_SUCCESS);
}
else
{
printf("%cPlease input a valid option.\n",7);
continue;
}
}
continue;
}
}
/* Function for division quiz */
int divisionquiz()
{
/* Randomizing the division quiz */
int a,b,diff,ans,again,remain;
a=0;
diff=1;
if(a>9)
{
a=0;
diff++;
}
if(diff>9);
{
diff=0;
}
b=a+diff;
if(b>9);
{
b=0;
}
/*Main part of the division quiz */
while(1==1)
{
/* Not allowing division by 0 or answers less than 1 */
if(numbers[b]==0 || (numbers[a]<numbers[b]))
{
a++;
continue;
}
printf("%d %% %d =\n",numbers[a],numbers[b]);
printf("What is the whole number in your answer?\n");
scanf("%d",&ans);
printf("\nWhat is the remainder in your answer?(0 if none)\n");
scanf("%d",&remain);
if((ans==numbers[a]/numbers[b])&&(remain==numbers[a]%numbers[b]))
{
printf("\nYour answer is CORRECT!!!\n");
a++;
}
else
{
printf("\nYour answer is WRONG!!!\n");
divisionquiz();
}
/* Loop for division quiz */
while(1==1)
{
printf("\n1 - Answer another division question\n2 - Go back to main menu\n3 - Exit program\n");
scanf("%d",&again);
if(again==1)
{
clear();
break;
}
else if(again==2)
{
clear();
main();
}
else if(again==3)
{
exit(EXIT_SUCCESS);
}
else
{
printf("%cPlease input a valid option.\n",7);
continue;
}
}
continue;
}
}