#My loop not looping

4 messages · Page 1 of 1 (latest)

patent cometBOT
#

@true jewel

File Attachments Not Allowed

For safety reasons we do not allow files with certain file extensions.

nanohakase10 Said

It's a do-while loop, but it ain't looping. The cause is the scanf(), since the code works fine if that part is removed. But why is this so? How do I make it work?

Code Formatting

You can share your code using triple backticks like this:
```
YOUR CODE
```

Large Portions of Code

For longer scripts use Hastebin or GitHub Gists and share the link here

Ignored these files due to them having disallowed file extensions
  • quizGameBCSver.c
true jewel
#

oh okay.

#
#include <stdio.h>
#include <ctype.h>

int main(){

   

     char questions[][100] = {"What is the first letter of the english alphabet?",
                              "What is a subject that mostly involves numbers?",
                              "What year is divisible by 4?"};

     char choices[][50] = {"A. A \n B. C \n D. H \n C. Y \n",
                           "A. Biology \n B. Physics \n D. Maths \n C. English \n",
                           "A. 2005 \n B. 2009 \n C. 2078 \n D. 2024 \n"} ;      

     char answer[] = {'A', 'D', 'D'} ;                                      

    int NoOfQuestions = sizeof(questions)/ sizeof(questions[0]);

    //printf(" %s",choices[1]);

    int i = 0;

   do
   {
    //int i = 0;
   
     printf(" %s\n", questions[i]);
     printf(" %s\n", choices[i]);
      i++; 

     scanf(" %c", answer[i]);
     scanf( "%*c");
     answer[i] = toupper(answer[i]);


   } while (i < NoOfQuestions);
   
  





    /* 
    for(int i = 0; i < NoOfQuestions; i ++){
        printf(" %s", questions[i]);

        for(int j = 0; j  <  )
    } */

    return 0;
}




humble karma
#

What exactly is happening in your code? Maybe I can help, I'm also learning