c语言背单词小游戏
时间: 2023-06-21 08:10:12 浏览: 51
好的,下面是一个简单的C语言背单词小游戏:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define MAX_WORDS 10
#define MAX_WORD_LEN 20
char words[MAX_WORDS][MAX_WORD_LEN] = {
"apple",
"banana",
"cherry",
"orange",
"pear",
"grape",
"watermelon",
"pineapple",
"kiwi",
"strawberry"
};
int main() {
srand(time(NULL));
int score = 0;
for (int i = 0; i < MAX_WORDS; i++) {
int index = rand() % MAX_WORDS;
printf("Please enter the English word for the Chinese word: %s\n", words[index]);
char answer[MAX_WORD_LEN];
scanf("%s", answer);
if (strcmp(answer, words[index]) == 0) {
printf("Correct!\n");
score++;
} else {
printf("Incorrect, the correct answer is %s\n", words[index]);
}
}
printf("Game over, your score is %d\n", score);
return 0;
}
```
这个小游戏会随机从一个单词列表中选出一个单词,然后让玩家输入这个单词的英文翻译。如果答对了,得一分;答错了,不得分,同时给出正确答案。最后显示总得分。