昨日は同じ問題のプログラム(ASCIIコンバーターなど)を作ることができました[プログラムを作成するときにすべての関数にプロトタイプエラーがありませんでした]ランダムな試行錯誤で修正できました。それ。これが私の算数クイズの練習プログラムです。また、int initialize()、clear()、exit()、additionquiz()、subtractionquiz()、divisionquiz()、multiplicationquiz();を入れてみました。そしてそれはまだ私に行方不明のプロトタイプを与えました。
#include <stdio.h>
/* Main Menu */
int numbers[10];
int main()
{
while(1==1)
{
int choice;
initialize();
printf("Arithmetic Quiz Program\n");
printf("1 - Addition\n2 - Subtraction\n3 - Multiplication\n4 - Division\n5 - Exit\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();
}
else
{
printf("%cPlease choose a number from 1 - 5",7);
clear();
continue;
}
}
return 0;
}
/* For clearing the page */
int clear()
{
int i;
for(i=0;i<25;i++)
{
printf("\n");
}
}
/* Assigns the array */
int initialize()
{
numbers[0]=6;
numbers[1]=0;
numbers[2]=2;
numbers[3]=5;
numbers[4]=3;
numbers[5]=1;
numbers[6]=9;
numbers[7]=4;
numbers[8]=7;
numbers[9]=8;
return 0;
}
/* addition quiz */
int addition()
{
int a,diff,b,answer,choice;
a=0;
diff=1;
b=a+diff;
while(1==1)
{
if(a>9)
{
a=0;
diff++;
}
if(b>9)
{
b=0;
}
if(diff>9)
{
diff=0;
}
printf("%d + %d = ",number[a],number[b]);
scanf("%d",&answer);
if(answer==number[a]+number[b])
{
printf("\nCORRECT!!!\n");
a++;
}
else
{
printf("\nWRONG!!!\n");
clear();
additionquiz();
}
printf("\nWhat do you want to do next?\n1 - Answer another addition Question\n2 - Go back to main menu\n3 - Exit program\n");
scanf("%d",&choice);
if(choice==1)
{
clear();
additionquiz();
}
else if(choice==2)
{
clear();
main();
}
else if(choice==3)
{
exit();
}
else
{
printf("%cPlease choose a number from 1 to 3",7);
}
}
return 0;
}
/* The subtraction quiz */
int subtraction()
{
int a,diff,b,answer,choice;
a=0;
diff=1;
b=a+diff;
while(1==1)
{
if(a>9)
{
a=0;
diff++;
}
if(b>9)
{
b=0;
}
if(diff>9)
{
diff=0;
}
if(numbers[a]-numbers[b]<0)
{
a++;
subtraction();
}
printf("%d - %d = ",numbers[a],numbers[b]);
scanf("%d",&answer);
if(answer==numbers[a]-numbers[b])
{
printf("CORRECT!!!\n\n");
}
else
{
printf("WRONG!!!\n\n");
clear();
subtractionquiz();
}
printf("\nWhat do you want to do next?\n1 - Answer another subtraction Question\n2 - Go back to main menu\n3 - Exit program\n");
scanf("%d",&choice);
if(choice==1)
{
clear();
subtractionquiz();
}
else if(choice==2)
{
clear();
main();
}
else if(choice==3)
{
exit();
}
else
{
printf("%cPlease choose a number from 1 to 3",7);
}
}
return 0;
}
/* multiplication quiz */
int multiplicationquiz()
{
int a,diff,b,answer,choice;
a=0;
diff=1;
b=a+diff;
while(1==1)
{
if(a>9)
{
a=0;
diff++;
}
if(b>9)
{
b=0;
}
if(diff>9)
{
diff=0;
}
printf("%d * %d = ",number[a],number[b]);
scanf("%d",&answer);
if(answer==number[a]*number[b])
{
printf("\nCORRECT!!!\n");
a++;
}
else
{
printf("\nWRONG!!!\n");
clear();
multiplicationquiz();
}
printf("\nWhat do you want to do next?\n1 - Answer another multiplication Question\n2 - Go back to main menu\n3 - Exit program\n");
scanf("%d",&choice);
if(choice==1)
{
clear();
multiplicationquiz();
}
else if(choice==2)
{
clear();
main();
}
else if(choice==3)
{
exit();
}
else
{
printf("%cPlease choose a number from 1 to 3",7);
}
}
return 0;
}
/* Division quiz */
int divisionquiz()
{
int a,diff,b,answer,choice,remain;
a=0;
diff=1;
b=a+diff;
while(1==1)
{
if((numbers[a]<numbers[b])||numbers[b]==0)
{
a++;
clear();
divisionquiz();
}
if(a>9)
{
a=0;
diff++;
}
if(b>9)
{
b=0;
}
if(diff>9)
{
diff=0;
}
printf("%d % %d = \n",numbers[a],numbers[b]);
printf("What is the whole number?\n");
scanf("%d",&answer);
printf("What is the remainder? (0 if none\n)");
scanf("%d",&remain);
if(answer==numbers[a]/numbers[b] && remain==numbers[a]%numbers[b])
{
printf("\nCORRECT!!!");
a++;
}
else
{
printf("\nWRONG!!!");
clear();
divisionquiz();
}
printf("\nWhat do you want to do next?\n1 - Answer another division Question\n2 - Go back to main menu\n3 - Exit program\n");
scanf("%d",&choice);
if(choice==1)
{
clear();
divisionquiz();
}
else if(choice==2)
{
clear();
main();
}
else if(choice==3)
{
exit();
}
else
{
printf("%cPlease choose a number from 1 to 3",7);
}
}
return 0;
}