PDA

View Full Version : اصلاح خطا



کارآموز کوچک
دوشنبه 24 آذر 1393, 21:24 عصر
سلام
وقت همگی به خیر
استادمون یک پروژه به زبان C داده که در مورد یک برنامه آموزشی که به دبستانی ها در یادگیری چهار عمل ریاضی کمک میکنه.این برنامه یه منوی اصلی 6تایی داره که انتخاب میکنه چه عملی رو می خواد یاد بگیره بعد توی هر کدوم یه منوی4تایی داره که 3تای اول سطح سوالات رو مشخص میکنه و گزینه آخر Back که وقتی انتخابش میکنی باید بره به منوی اصلی.تا زماني كه دانش آموز تمايل به تمرين و يادگيري داره، برنامه به ارائه سوالات ادامه میده.در صورتي كه دانش آموز از منوي اصلي، گزينه "All Learning " را انتخاب كرده باشه؛ به ازاي هر سوال، نوع عملگر توسط برنامه و به صورت تصادفي انتخاب میشه.
میخواستم کدهایی رو که نوشته بذارم وبهم بگین چطوری اصلاحش کنم تا بهتر بشه. من خودم توی گزینه های Back, All learning خیلی مشکل دارم باید چوری بنویسمشون.
خیلی ممنون میشم اگه راهنماییم بکنید.:لبخندساده:



#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void time(int,int);
void meno(void);
void show (void);
void add (void);
void subtraction (void);
void multiplication (void);
void division (void);
void all (void);
void main()
{
int num;
meno();
printf("\nEnter the number:");
scanf("%d",&num);
switch (num)
{
case 1:
add();
case 2:
subtraction();
case 3:
multiplication();
case 4:
division();
case 5:
all();
case 6:
printf("Press any key to exit");
break;
}
getch();
}
void time(int t1, int t2)
{
int t,h,p,m,s;
t=t2-t1;
h=t/3600;
p=t%3600;
m=p/60;
s=p%60;
printf("\ntime %d:%d:%d",h,m,s);
}
void meno(void)
{
printf("1.Add learning");
printf("\n2.Subtraction learning");
printf("\n3.Multiplication learning");
printf("\n4.Division learning");
printf("\n5.All learning");
printf("\n6.Exit");
}
void show (void)
{
printf("\n1.Beginning Level");
printf("\n2.Intermediate Level");
printf("\n3.Advanced Level");
printf("\n4.Back");
}
void add (void)
{
show();
char y,n,rep;
do
{
srand(time(0));
int num1,num2,num,ans;
printf("\nEnter the number:");
scanf("%d",&num);
switch (num)
{
case 1:
{
int num1,num2;
num1=rand()%100;
num2=rand()%10;
int t1=(time(0));
printf("num1=%d,num2=%d",num1,num2);
printf("\nPlease enter answer:");
scanf("%d",&ans);
int t2=(time(0));
if(ans==num1+num2)
printf("very good");
else
printf("Try again");
time(t1,t2);
break;
}
case 2:
{
int num1,num2;
num1=rand()%1000;
num2=rand()%100;
int t1=(time(0));
printf("num1=%d,num2=%d",num1,num2);
printf("\nPlease enter answer:");
scanf("%d",&ans);
int t2=(time(0));
if(ans==num1+num2)
printf("very good");
else
printf("Try again");
time(t1,t2);
break;
}
case 3:
{
int num1,num2;
num1=rand()%100000;
num2=rand()%1000;
int t1=(time(0));
printf("num1=%d,num2=%d",num1,num2);
printf("\nPlease enter answer:");
scanf("%d",&ans);
int t2=(time(0));
if(ans==num1+num2)
printf("very good");
else
printf("Try again");
time(t1,t2);
break;
}
case 4:
{
meno();
break;
}
default:
printf("Please enter the correct number.");
break;
}
printf("\nDo you continue? (y/n):");
rep=getche();

}while(rep!='n');
printf("\nPress any key to exit");
}
void subtraction (void)
{
show();
char y,n,rep;
do
{
srand(time(0));
int num1,num2,num,ans;
printf("\nEnter the number:");
scanf("%d",&num);
switch (num)
{
case 1:
{
int num1,num2;
num1=rand()%100;
num2=rand()%10;
int t1=(time(0));
printf("num1=%d,num2=%d",num1,num2);
printf("\nPlease enter answer:");
scanf("%d",&ans);
int t2=(time(0));
if(ans==num1-num2)
printf("very good");
else
printf("Try again");
time(t1,t2);
break;
}
case 2:
{
int num1,num2;
num1=rand()%1000;
num2=rand()%100;
int t1=(time(0));
printf("num1=%d,num2=%d",num1,num2);
printf("\nPlease enter answer:");
scanf("%d",&ans);
int t2=(time(0));
if(ans==num1-num2)
printf("very good");
else
printf("Try again");
time(t1,t2);
break;
}
case 3:
{
int num1,num2;
num1=rand()%100000;
num2=rand()%1000;
int t1=(time(0));
printf("num1=%d,num2=%d",num1,num2);
printf("\nPlease enter answer:");
scanf("%d",&ans);
int t2=(time(0));
if(ans==num1-num2)
printf("very good");
else
printf("Try again");
time(t1,t2);
break;
}
case 4:
{
meno();
break;
}
default:
printf("Please enter the correct number.");
break;
}
printf("\nDo you continue?(y/n):");
rep=getche();
}while(rep!='n');
printf("\nPress any key to exit");
}
void multiplication (void)
{
show();
char y,n,rep;
do
{
srand(time(0));
int num1,num2,num,ans;
printf("\nEnter the number:");
scanf("%d",&num);
switch (num)
{
case 1:
{
int num1,num2;
num1=rand()%10;
num2=rand()%10;
int t1=(time(0));
printf("num1=%d,num2=%d",num1,num2);
printf("\nPlease enter answer:");
scanf("%d",&ans);
int t2=(time(0));
if(ans==num1*num2)
printf("very good");
else
printf("Try again");
time(t1,t2);
break;
}
case 2:
{
int num1,num2;
num1=rand()%1000;
num2=rand()%10;
int t1=(time(0));
printf("num1=%d,num2=%d",num1,num2);
printf("\nPlease enter answer:");
scanf("%d",&ans);
int t2=(time(0));
if(ans==num1*num2)
printf("very good");
else
printf("Try again");
time(t1,t2);
break;
}
case 3:
{
int num1,num2;
num1=rand()%100000;
num2=rand()%1000;
int t1=(time(0));
printf("num1=%d,num2=%d",num1,num2);
printf("\nPlease enter answer:");
scanf("%d",&ans);
int t2=(time(0));
if(ans==num1*num2)
printf("very good");
else
printf("Try again");
time(t1,t2);
break;
}
case 4:
{
meno();
break;
}
default:
printf("Please enter the correct number.");
break;
}
printf("\nDo you continue?(y/n):");
rep=getche();
}while(rep!='n');
printf("\nPress any key to exit");
}
void division (void)
{
show();
char y,n,rep;
do
{
srand(time(0));
int num1,num2,num,quo,rem;
printf("\nEnter the number:");
scanf("%d",&num);
switch (num)
{
case 1:
{
int num1,num2;
num1=rand()%10;
num2=rand()%10;
int t1=(time(0));
printf("num1=%d,num2=%d",num1,num2);
printf("\nPlease enter the quotient:");
scanf("%d",&quo);
printf("Please enter remaining:");
scanf("%d",&rem);
int t2=(time(0));
if(quo==num1/num2 && rem==num1%num2 )
printf("very good");
else
printf("Try again");
time(t1,t2);
break;
}
case 2:
{
int num1,num2;
num1=rand()%1000;
num2=rand()%10;
int t1=(time(0));
printf("num1=%d,num2=%d",num1,num2);
printf("\nPlease enter quotient:");
scanf("%d",&quo);
printf("Please enter remaining:");
scanf("%d",&rem);
int t2=(time(0));
if(quo==num1/num2 && rem==num1%num2 )
printf("very good");
else
printf("Try again");
time(t1,t2);
break;
}
case 3:
{
int num1,num2;
num1=rand()%100000;
num2=rand()%1000;
int t1=(time(0));
printf("num1=%d,num2=%d",num1,num2);
printf("\nPlease enter quotient:");
scanf("%d",&quo);
int t2=(time(0));
if(quo==num1/num2 && rem==num1%num2 )
printf("very good");
else
printf("Try again");
time(t1,t2);
break;
}
case 4:
{
meno();
break;
}
default:
printf("Please enter the correct number.");
break;
}
printf("\nDo you continue?(y/n):");
rep=getche();
}while(rep!='n');
printf("\nPress any key to exit");
}
void all(void)
{
srand(time(0));
int numb;
numb=rand()%4;
if (numb==1)
{
printf("Add learning(+)");
add ();
}
else if (numb==2)
{
printf("Subtraction learning(-)");
subtraction ();
}
else if (numb==3)
{
printf("Multiplication learning(*)");
multiplication ();
}
else if (numb==4)
{
printf("Division learning(/)");
division ();
}
}