c - Why doesn't my for loop exit? -


c program. trying make multiple choice quiz. have used loop run question 1 2 3 etc. after running program never exits loop when have specified count <=3. why? can see have done wrong?

#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' si or 'n' no.\n");     scanf ("%c",&s);           if (s='s'){                 printf ("bueno. ya empezamos!\n");                 }         (count=0;count<=3;count++){         printf ("1.que significa la palabra 'conocer'\n");         printf ("1.\t 2.\t know\t 3. do\t 4. eat\n");           scanf ("%d",&x);         if (x=response[1])         {         printf ("equivocado!\n 'conocer'significa: know\n");                     }        else {        printf ("correcto!\n");         }         printf ("1.que significa la palabra 'ser'\n");         printf ("1.\t 2.\t return\t 3. (location)\t 4. eat\n");         scanf ("%d",&x);         if (x=response[0])         {            printf ("equivocado!\n 'ser'significa: be\n");         }        else {             printf ("correcto!\n");         }        printf ("1.que significa la palabra 'poder'\n");         printf ("1.\tto able 2.\t run\t 3. play\t 4. put\n");           scanf ("%d",&x);         if (x=response[0])         {         printf ("equivocado!\n 'poder'significa: able to\n");                     }        else {        printf ("correcto!\n");          }        result=(4/count)*100;        printf ("%d percentage out of %d attempts\n",result,count);         }   return 0; } 

  • your declaration of int x erroneous; there's comma next identifier.
  • in c, comparison operator looks ==, not =. this assignment operator.
  • your percent calculation wrong; int / int int not float or double or long double, 0. furthermore, float printed out "%f" format string.

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -