我现在完全茫然了。
我已经尝试了无数次来使我的程序正常运行,但是那只是不想做。
快速概述:
我目前正在编写一个小的词汇测验,该测验为用户提供了随机的英语术语,并且用户必须使用正确的德语术语进行回答。 测验结束后,它将显示正确/错误答案的数量。
英语和德语术语都存储在二维数组中,我一生无法解决如何确保正确的德语术语固定在相应的英语单词上的问题。
代码如下:
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <windows.h>
char eng[15][400]={"House","Lunatic","Nondescript","Ubiquity","Barley","Cardiac Arrest","Foreclosure",
"Thunderstorm","The answer to life, the universe and everything","Singularity"};
char ger[15][200]={"Haus","Irrer","nichtssagend","Allgegenwart","Gerste","Herzstillstand","Zwangsvollstreckung",
"Gewitter","42","Besonderheit"};
int i,corr=0,wrong=0,rnd, counter=0;
int choice[5];
int inArray;
char D[40];
int main(){
srand(time(NULL));
for(int i=0;i<5;i++) choice[i]=-1;
while(counter < 5){
rnd = rand()%10;
inArray = 0;
for(int i=0; i<5; i++){
if(choice[i] == rnd){
inArray = 1;
}
}
if(!inArray){
printf("\nQuestion number %d : %s\nPlease enter your answer: ", counter, eng[rnd]);
gets(D);
if(D==ger[rnd]){
corr++;
}
else{
wrong++;
}
choice[counter] = rnd;
counter++;
}
}
Sleep(1000);
printf("\n\n\n# of correct answers: %d\n# of false answers: %d",corr,wrong);
return 0;
getchar();
}
附录:我对正确/错误答案的计数器似乎也坏了,对此有什么想法吗?
答案 0 :(得分:1)
您可以尝试使用struct:
#include "stdio.h"
struct word {
char *eng;
char *ger;
};
struct word voc[] = {
{"House", "Haus"},
{"Lunatic", "Irrer"}
//etc...
};
int main() {
printf("%s %s\n", voc[1].eng, voc[1].ger);
return 0;
}
// Lunatic Irrer
(将char指针用于静态字符串)