#include<stdlib.h>
void main(void)
{
int a,b//两个乘族橡渗数
int c //学生输兆脊入的答案
while(true)
{
a = rand() % 10 + 1
b = rand() % 10 + 1
printf("%d * %d = ?\n", a, b)
scanf("%d", &c)
if(c == a * b)
{
printf("Right!\n")
}
else
{
//再给三次机会
int chance = 3
while(chance >0)
{
printf("Wrong! Please try again.\n")
scanf("%d", &c)
if(c == a * b)
{
printf("Right!\n")
break
}
chance --
}
//三次都不对,程序结束
if(chance == 0)
{
printf("Wrong! You have tried three times! Test over!\n")
return
}
}
}
}
class Program{
static void Main(string[] args)
{
string questFormat = "How much is {0} times {1}?"
string rightStr = "皮亮Very good! Excel lent! Nice work! Keep up the good work!"
string[] wrongStr = new string[] { "No, Please try again."配闷, "Wrong, Try once more.", "Don’t give up!"燃卖宽, "No, Keep trying." }
Random random = new Random()
while (true)
{
int a = random.Next(0, 10)
int b = random.Next(0, 10)
int c = 0
while (true)
{
Console.WriteLine(questFormat, a, b)
if (int.TryParse(Console.ReadLine(), out c))
{
if (c == a * b)
{
Console.WriteLine(rightStr)
break
}
}
Console.WriteLine(wrongStr[random.Next(0, 4)])
}
}
}
}
Qbasic:Randomize Timer
INPUT "N="N
For i = 1 To N
k = Int(Rnd * 4)
Select Case k
Case 0:
a = Int(Rnd * 11)
b = Int(Rnd * 11)
e$ = "友迅+"
c = a + b
Case 1:
c = Int(Rnd * 11)
b = Int(Rnd * 11)
e$ = "-"
a = b + c
Case 2:
a = Int(Rnd * 10)
b = Int(Rnd * 10)
e$ = "*"
c = a * b
Case 3:
c = Int(Rnd * 10)
b = Int(Rnd * 9) + 1
e$ = "/"
a = b * c
End Select
Print ae$b"拆汪="
INPUT d
If c = d Then
Print "right!"
Else
Print "Wrong!"旅告仔
End If
Next i
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)