Thread: C (Making quiz in c language,using filling)how the user can go to next question.reply

  1. #1
    Registered User
    Join Date
    Jul 2016
    Posts
    4

    C (Making quiz in c language,using filling)how the user can go to next question.reply

    I am making a quiz using c language.I want to read all the questions from the file and so that when the questions is printed on the screen the user can choose the answer and then the user can go onto the next question.please help.wasted 2 hours still don't know how. please reply.thanks in advance.
    Last edited by Khurram Ali; 07-16-2016 at 03:33 PM.

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,106
    please reply asap.thanks in advance.
    Homework due tomorrow?

    Please read the Announcements at top of this forum especially the policy about homework!

    We are not here to do the work for you. You need to post your attempt, and ask questions about the code YOU wrote, then we can attempt to guide you in the right direction.

    Please DO NOT expect an answer, ASAP! That is VERY rude here.

  3. #3
    Registered User
    Join Date
    Jul 2016
    Posts
    4
    its not homework.i am trying to make the program.So can you help?

  4. #4
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,106
    Homework or not, we are not here to write code for you. ONLY to comment on code YOU have written and have questions about.

    When you do present code, please keep the sample code as small as possible that demonstrates the problem, and that we can compile.

    Please turn on and turn up your warning level to the highest setting so you see all the problems with the code that the compiler has seen.

  5. #5
    Registered User
    Join Date
    Jul 2016
    Posts
    4
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <ctype.h>
    #include <string.h>
    
    
    
    
    
    
    int main(){
    
    
    int level;
    char option,choice;
    
    
    
    
        printf("\tQuiz related to IT & G.K.\n\n");
        printf("\tPress S to start the quiz.\n\n");
        printf("\tPress V to view score.\n\n");
        printf("\tPress H for help.\n\n");
        printf("\tPress Q to quit.\n\n");
        printf("_______________________________________\n\t");
        scanf("%c",&option);
    
    
        if(option=='S'||option=='s'){
    
    
        printf("_______________________________________\n");
        printf("\tChoose a difficulty level:\n\t1)Easy.\n\t2)Medium.\n\t3)Hard.\n");
        printf("_______________________________________\n\t");
    
    
        scanf("%d",&level);
    
    
        if(level==1){
    
    
                system("cls");
    
    
        printf("\tQuiz started!\t\t\t\t\t\t\t\t\tTime Allowed:30MIN\n\n\t");
    
    
    
    
    
    
    
    
    FILE *fp;
    
    
    fp = fopen("sample.txt", "r");
    
    
    char ques[200];
    
    
    while(!feof(fp)){
        fgets(ques,200,fp);
        puts(ques);
    
    
    }
    fclose(fp);
    
    
    scanf("%c",&choice);
    
    
    if (choice=='B'&&choice=='C'&&choice=='D')
    
    
        printf("Incorrect answer,A is the right answer\n\t");
    
    
    else
    
    
        printf("Correct\n\t");
    
    
    return 0;
    
    
        }
    
    
        }
    
    
        }

  6. #6
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,106
    What questions do you have?

    What problems are you having?

  7. #7
    Registered User
    Join Date
    Jul 2016
    Posts
    4
    i want to print one question and ask the user for input ,one at a time from the file.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > if (choice=='B'&&choice=='C'&&choice=='D')
    Presumably, the correct answer will vary from one question to another.

    Which then leads onto - where is the correct answer stored? Is it part of the question file "sample.txt"?

    At the moment, you're just printing the whole file.

    You need a loop which prints one question at a time.

    Let's say a question occupies 6 lines, like so

    Life is known to exist on which planet:
    A - Mercury
    B - Venus
    C - Earth
    D - Mars
    C

    The first 5 lines contain the question and the choices.
    The 6th line contains the correct response.

    Your loop needs to read and print the first 5 lines, and then read (but don't print) the 6th line.

    You then read a response from the user, and compare with the correct answer.

    The whole thing repeats until there are no more questions in the file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,106
    I think you need to take a step back and rethink the algorithm for the program BEFORE you start to code the program, taking in consideration the comments that @Salem made previously.

    I would recommend writing pseudo-code on paper, or in a word processor outline to lay out the program BEFORE you start to code in C. The latter is my preference so I can re-arrange the lines more easily if my thought process is backwards.

    If you are not familiar with pseudo-code, many tutorials are available, one of which is here.

    After you work out the algorithm in pseudo-code, then I would rewrite your code from scratch rather than trying to fix the code presented.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making a math quiz program
    By mackieinva in forum C Programming
    Replies: 10
    Last Post: 09-17-2007, 03:38 PM
  2. Quick Reply or Normal Reply
    By Thantos in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 05-18-2004, 12:49 PM
  3. How would I go about making a scripting language...
    By gcn_zelda in forum C++ Programming
    Replies: 1
    Last Post: 06-19-2003, 11:43 AM
  4. C programming language quiz
    By Trancongan in forum C Programming
    Replies: 7
    Last Post: 04-21-2002, 01:04 PM
  5. best language for making games?
    By Unregistered in forum Game Programming
    Replies: 9
    Last Post: 11-09-2001, 05:37 AM

Tags for this Thread