C程序。我正在嘗試進行多項選擇測驗。我已經使用for循環從問題1運行到2到3等。但是,運行程序後,即使我只指定了計數< = 3,它也不會退出for循環。爲什麼?你能看到我做錯了什麼嗎?爲什麼我的for循環退出?
#include <stdio.h>
int main (void)
{
char s;
char response[]={'a','b','c','d'};
int ,x;
int count,result;
printf (" Listo para empezar?\n\n Please type 's' for si or 'n' for no.\n");
scanf ("%c",&s);
if (s='s'){
printf ("Bueno. Ya Empezamos!\n");
}
for (count=0;count<=3;count++){
printf ("1.Que significa la palabra 'conocer'\n");
printf ("1.\t to like 2.\t to know\t 3. to do\t 4. to eat\n");
scanf ("%d",&x);
if (x=response[1])
{
printf ("Equivocado!\n 'conocer'significa: to know\n");
}
else {
printf ("Correcto!\n");
}
printf ("1.Que significa la palabra 'ser'\n");
printf ("1.\t to be 2.\t to return\t 3. to be (location)\t 4. to eat\n");
scanf ("%d",&x);
if (x=response[0])
{
printf ("Equivocado!\n 'ser'significa: to be\n");
}
else {
printf ("Correcto!\n");
}
printf ("1.Que significa la palabra 'poder'\n");
printf ("1.\tto be able to 2.\t to run\t 3. to play\t 4. to put\n");
scanf ("%d",&x);
if (x=response[0])
{
printf ("Equivocado!\n 'poder'significa: to be able to\n");
}
else {
printf ("Correcto!\n");
}
result=(4/count)*100;
printf ("%d is your percentage out of %d attempts\n",result,count);
}
return 0;
}
'if(s ='s')'look look grepicious。 (你似乎很多時候使用==) – teppic 2015-04-01 13:07:00
所示的代碼不會編譯。 – 2015-04-01 13:07:32
'int,x;'嚴重嗎? – 2015-04-01 13:11:20