Thread: Need help how to randomized questions

  1. #1
    Registered User
    Join Date
    Sep 2016
    Posts
    2

    Need help how to randomized questions

    hi guys i need some help how can i make those questions randomized when its played. i am a newbie and in my first year college. please suggest or comment some things that i can do to improve my work. thanks.
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<dos.h>
    #include<stdlib.h>
    #define pf printf
    #define sf scanf
    
    
    main()
    
    
    {
    char name[100],yrs[100];
    int n,letter;
    
    
    textcolor(BLACK);
    textbackground(WHITE);
    clrscr();
    pf("\n===========================================================================");
    pf("\n*                         Please Fill Up The Following                    *");
    pf("\n*=========================================================================*");
    pf("\n*                                                                         *");
    pf("\n*                     Enter Your Name:                                    *");
    pf("\n*                                                                         *");
    pf("\n*                   Enter Your Course:                                    *");
    pf("\n*                                                                         *");
    pf("\n===========================================================================");
    gotoxy(40,6);
    sf("%s",&name);
    gotoxy(40,8);
    sf("%s",&yrs);
    
    
    clrscr();
    
    
    pf("\n===========================================================================");
    pf("\n|                        *Coded by:BSEMC-1A S Y 2016*                     |");
    pf("\n|-------------------------------------------------------------------------|");
    pf("\n                                                                        ");
    pf("\n                   ------- WELCOME %s TO QUIZ GAME! --------             ",name);
    pf("\n                                                                      ");
    pf("\n|-------------------------------------------------------------------------|");
    pf("\n|                            LOADING PLEASE WAIT...                       |");
    pf("\n=========================================================================== ");
    delay (60);
    clrscr();
    pf("\nPlayer :%s                                                       Course:%s",name,yrs);
    pf("\n============================================================================== ");
    pf("\t\t                    ----CHOOSE YOUR MODE----");
    pf("\n             1.....................................EASY");
    pf("\n             2.....................................MEDIUM");
    pf("\n             3.....................................DIFFICULT");
    pf("\n\n                PLEASE ENTER YOUR CHOICE:                                        ");
    pf("\n============================================================================== ");
    gotoxy(42,9);
    sf("%d",&letter);
    
    
    switch (letter);
    
    
     {
     char a,b,c;
     int x=0
     ;
     clrscr();
     pf("\nPlayer :%s                                                       Course:%s",name,yrs);
     pf("\n============================================================================== ");
     pf("\nEASY MODE ..................................................Question 1 ot of 10");
     pf("\n============================================================================== ");
    
    
     pf("\nWhat did the ancient Greeks use instead of soap ?");
     pf("\nA.Olive Oil\nB.coconut\nC.Nectar\nD.Butter");
    
    
     pf("\n\n Your answer: ");
     sf("%s",&a);
    
    
    if (a=='a' || a=='A')
     {
     x=x+1;
     printf("\n                                 CORRECT!   \n");
     }
     else
    
    
     pf("\n                     WRONG! The Correct Answer Is A");
    getch();
    clrscr();
    pf("\nPlayer :%s                                                       Course:%s",name,yrs);
     pf("\n============================================================================== ");
     pf("\nEASY MODE .................................................Questions 2 ot of 10");
     pf("\n============================================================================== ");
    pf(" Which Apollo mission landed the first humans on the Moon?");
    
    
    pf("\nA.Apollon 7\nB.Apollo 9\nC.Apollo 11\nD.Apollo 13");
    
    
    pf("\n Your Answer: ");
    sf("%s",&b);
    
    
    if (b=='c' || b=='C')
     {
     x=x+1;
     printf("\n                                 CORRECT!   \n");
     }
    else
    
    
    pf("\n                     WRONG! The Correct Answer Is C");
    getch();
    clrscr();
    pf("\nPlayer :%s                                                       Course:%s",name,yrs);
     pf("\n============================================================================== ");
     pf("\nEASY MODE .................................................Questions 3 ot of 10");
     pf("\n============================================================================== ");
    pf("\n Who plays Lara Croft in the Tomb Raider series of films?'");
    
    
    
    
    pf("\n A.Angelina Jolie\nB.Minnie Driver\nC.Nell McAndrew\nD.Jennifer Aniston");
    pf("\n Your Answer: ");
    sf("%s",&c);
    if (c=='a' || c=='A')
     {
     x=x+1;
     printf("\n                                 CORRECT!   \n");
     }
    else
    
    
    pf("\n                     WRONG! The Correct Answer Is A");
     clrscr();
     if (x==30)
     pf("\n            PERFECT SCORE!:%d \n",x);
    
    
     else if (x<30)
     pf("\n            YOUR TOTAL SCORE IS: %d OUT OF 3",x);
     sf("%d",&letter);
    
    
     }
    
    
    getch();
    return 0;
    }

    thanks guys..

  2. #2
    Registered User
    Join Date
    Sep 2016
    Posts
    2
    im using DOSBOX there

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Things you can do to improve:

    1. Stop using Turbo C. It was already obsolete 20 years ago. Your school probably uses it because it's free. There are better, newer compilers that are free.
    2. Don't use #define to rename functions like printf and scanf. Code needs to be readable by humans, and the humans who have to read your code shouldn't have to reference a list of #define statements to figure out what it's doing.
    3. Don't rely on default return types. It should be
    Code:
    int main(void)
    or
    Code:
    int main(int argc, char** argv)
    4. Always initialize your variables when you declare them.
    5. Don't include headers you don't use (dos.h in this case).
    6. Use more consistent formatting and indentation.
    Code:
    #include <stdio.h>
    
    int main(void)
    {
        int i = 0; /* always initialize your variables! */
        for (i = 0; i < 10; ++i)
        {
            if (i % 2)
            {
                printf("i is odd");
            }
            else
            {
                printf("i is even");
            }
        }
    }
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > i am a newbie and in my first year college.
    Are you allowed to use things like arrays and structures yet?
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 12-21-2012, 11:48 PM
  2. Randomized Quicksort problem
    By Grigoris Savvas in forum C Programming
    Replies: 2
    Last Post: 04-06-2012, 11:33 PM
  3. Randomized multiple choice
    By Chucker in forum C Programming
    Replies: 5
    Last Post: 02-20-2012, 07:27 PM
  4. Generating ranged randomized numbers
    By Cloud_909 in forum C++ Programming
    Replies: 8
    Last Post: 12-05-2005, 05:42 PM
  5. randomized version generally doesn't work
    By talz13 in forum C++ Programming
    Replies: 7
    Last Post: 11-08-2003, 12:39 PM

Tags for this Thread