could anyone help me?

This is a discussion on could anyone help me? within the C Programming forums, part of the General Programming Boards category; This is something what i had done. I just wanna ask that how to avoid the error when i key ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    6

    could anyone help me?

    This is something what i had done. I just wanna ask that how to avoid the error when i key in a character when i'm using a switch-case function?
    and how do i set the numbers of decimal places of a float?because i'm dividing numbers, e.g. 10/3. it will generate 0.33333333333.....so, when i ask the user to key in answer, i need them to key in two decimal places only. but, in my program, when they key in only two decimal places, it shows that the answer key in is not equivalent to the answer required. for your information, i'm using function if to determine whether the answer is correct.thank you.
    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <dos.h>
    #include <stdlib.h>
    
    
    int num_easy,num_medium,num_hard, x, y,num_easy2, num_medium2, num_hard2;
    
    int random_easy(void);
    int random_easy2(void);
    int random_medium(void);
    int random_medium2(void);
    int random_hard(void);
    int random_hard2(void);
    int campur (int num1, int num2);
    int tolak (int num1, int num2);
    int darab (int num1, int num2);
    float bahagi (float num1, float num2);
    void operasi (void);
    void start_game_easy (void);
    void start_game_medium (void);
    void start_game_hard (void);
    void menu_level (void);
    void operasi (void);
    
    
    main()
    {FILE *input;
    input=fopen("data.txt", "w+");
    operasi();
    menu_level();
    
    
    fclose(input);
    getch();
    }
    
    int random_easy(void)
    {
    randomize();
    num_easy=rand()%10;
    return (num_easy);
    }
    
    int random_easy2(void)
    {
    randomize();
    num_easy2=random(10);
    return (num_easy2);
    }
    
    int random_medium(void)
    {
    
    randomize();
    num_medium=random(100)%100;
    if (num_medium<10)
    num_medium+=10;
    return (num_medium);
    }
    
    int random_medium2(void)
    {
    
    randomize();
    num_medium2=rand()%100;
    if (num_medium2<10)
    num_medium2+=10;
    return (num_medium2);
    }
    
    int random_hard(void)
    {
    
    randomize();
    num_hard=rand()%1000;
    if (num_hard<100)
    num_hard+=100;
    return (num_hard);
    }
    
    int random_hard2(void)
    {
    
    randomize();
    num_hard2=random(1000);
    if (num_hard2<100)
    num_hard2+=100;
    
    return (num_hard2);
    }
    
    int campur (int num1, int num2)
    {int jumlah;
    if (x==1)
    {num1=random_easy();num2=random_easy2();}else
    if (x==2)
    {num1=random_medium();num2=random_medium2();}else
    if (x==3)
    {num1=random_hard();num2=random_hard2();}
    
    printf(" %d + %d", num1, num2);
    jumlah=num1+num2;
    
    return (jumlah);
    }
    
    int tolak (int num1, int num2)
    {int jumlah;
    if (x==1)
    {num1=random_easy();num2=random_easy2();}else
    if (x==2)
    {num1=random_medium();num2=random_medium2();}else
    if (x==3)
    {num1=random_hard();num2=random_hard2();}
    printf(" %d - %d", num1, num2);
    jumlah=num1-num2;
    
    return (jumlah);
    }
    
    int darab (int num1, int num2)
    {int jumlah;
    if (x==1)
    {num1=random_easy();num2=random_easy2();}else
    if (x==2)
    {num1=random_medium();num2=random_medium2();}else
    if (x==3)
    {num1=random_hard();num2=random_hard2();}
    printf(" %d x %d", num1, num2);
    jumlah=num1*num2;
    
    return (jumlah);
    }
    
    float bahagi (float num1, float num2)
    {float jumlah;
    if (x==1)
    {num1=random_easy();num2=random_easy2();}else
    if (x==2)
    {num1=random_medium();num2=random_medium2();}else
    if (x==3)
    {num1=random_hard();num2=random_hard2();}
    printf(" %.2f / %.2f", num1,num2);
    jumlah=num1/num2;
    printf("\n%.2f",jumlah);
    return (jumlah);
    }
    
    
    
    
    void start_game_easy (void)
    {clrscr();
    int n=1;float jumlah_game_easy;
    float answer;
    while (n<=10)
    {clrscr();
    printf("\n\tSoalan Mudah");
    if (y==1)
    printf("\tOperasi Campur");else
    if (y==2)
    printf("\tOperasi Tolak");else
    if (y==3)
    printf("\tOperasi Darab");else
    if (y==4)
    printf("\tOperasi Bahagi");
    printf("\n\n\n\tAnda perlu menyelesaikan 10 soalan.");
    printf("\n\n\n\tCuba selesaikan soalan no. %d ini:", n);
    if (y==1)
    jumlah_game_easy=campur(num_easy, num_easy2);else
    if (y==2)
    jumlah_game_easy=tolak(num_easy,num_easy2);else
    if (y==3)
    jumlah_game_easy=darab(num_easy,num_easy2);else
    if (y==4)
    jumlah_game_easy=bahagi(num_easy,num_easy2);
    printf("\n\n\tJawapan > ");
     scanf("%f", &answer);
     if (answer==jumlah_game_easy)
     {printf("\n\tBetul...! Tambah 1 markah!");sleep(1);}else
     if (answer!=jumlah_game_easy)
     {printf("\n\tSalah...!");sleep(1);}
    n++;}
    
    }
    
    void start_game_medium (void)
    {clrscr();
    int n=1;
    float answer;float jumlah_game_medium;
    while (n<=10)
    {clrscr();
    printf("\n\tSoalan Biasa");
    if (y==1)
    printf("\tOperasi Campur");else
    if (y==2)
    printf("\tOperasi Tolak");else
    if (y==3)
    printf("\tOperasi Darab");else
    if (y==4)
    printf("\tOperasi Bahagi");
    printf("\n\n\n\tAnda perlu menyelesaikan 10 soalan.");
    printf("\n\n\n\tCuba selesaikan soalan no. %d ini:", n);
    if (y==1)
    jumlah_game_medium=campur(num_medium, num_medium2);else
    if (y==2)
    jumlah_game_medium=tolak(num_medium,num_medium2);else
    if (y==3)
    jumlah_game_medium=darab(num_medium,num_medium2);else
    if (y==4)
    jumlah_game_medium=bahagi(num_medium,num_medium2);
    printf("\n\n\tJawapan > ");
     scanf("%f", &answer);
     if (answer==jumlah_game_medium)
     {printf("\n\tBetul...! Tambah 2 markah!");sleep(1);}else
     if (answer!=jumlah_game_medium)
     {printf("\n\tSalah...!");sleep(1);}
    n++;}
    
    }
    
    
    void start_game_hard (void)
    {clrscr();
    int n;
    float answer,jumlah_game_hard;
    for (n=1;n<=10;n++)
    {clrscr();
    printf("\n\tSoalan Sukar");
    if (y==1)
    printf("\tOperasi Campur");else
    if (y==2)
    printf("\tOperasi Tolak");else
    if (y==3)
    printf("\tOperasi Darab");else
    if (y==4)
    printf("\tOperasi Bahagi");
    printf("\n\n\n\tAnda perlu menyelesaikan 10 soalan.");
    printf("\n\n\n\tCuba selesaikan soalan no. %d ini:", n);
    if (y==1)
    jumlah_game_hard=campur(num_hard, num_hard2);else
    if (y==2)
    jumlah_game_hard=tolak(num_hard,num_hard2);else
    if (y==3)
    jumlah_game_hard=darab(num_hard,num_hard2);else
    if (y==4)
    jumlah_game_hard=bahagi(num_hard,num_hard2);
    printf("\n\n\tJawapan > ");
     scanf("%f", &answer);
     if (answer==jumlah_game_hard)
     {printf("\n\tBetul...! Tambah 3 markah");sleep(1);}else
     if (answer!=jumlah_game_hard)
     {printf("\n\tSalah...!");sleep(1);}
    }
    
    }
    void menu_level (void)
    {
    repeat_menu:
    clrscr();
    
    printf("\n\n\n\t\t\tSila pilih tahap");
    
    printf("\n\n\t\t1.Easy\n\n\t\t2.Moderate\n\n\t\t3.Hard\n\n\t\t4.Menu Permainan\n");
    printf("\n\n\t\tPilihan > ");
     scanf("%d", &x);
     switch (x)
     {
     case 1:start_game_easy();break;
     case 2:start_game_medium();break;
     case 3:start_game_hard();break;
     case 4:{clrscr();operasi();};break;
     default:{printf("\n\n\t\tSalah input!");sleep(1);goto repeat_menu;};
     }
    
    }
    
    
    void operasi (void)
    {repeat:
    printf("\n\n\n\t\t\tMasukkan pilihan\n");
    printf("\n\t\t1.Add\n\n\t\t2.Minus\n\n\t\t3.Times\n\n\t\t4.Divide\n");
    printf("\n\n\t\tPilihan > ");
    
    scanf("%d", &y);
    
    switch (y)
    {
    case 1:menu_level();break;
    case 2:menu_level();break;
    case 3:menu_level();break;
    case 4:menu_level();break;
    default: {printf("\n\t\tSila masukkan pilihan 1,2,3,4 atau 5."); sleep(1);clrscr();goto repeat;};
     }
    }
    Last edited by Salem; 09-29-2004 at 11:15 AM. Reason: Quzah is my master

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Press the shiny, candy-like edit button, and add code tags to your post. Noone wants to read that the way it is. If you don't know how to add code tags, go back and read the Announcements.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    #include<xErath.h> xErath's Avatar
    Join Date
    Jun 2004
    Posts
    722
    Please use code tags...
    But
    Code:
    scanf("%d", &y);
    switch (x){
        case 1:start_game_easy();break;
        case 2:start_game_medium();break;
        case 3:start_game_hard();break;
        case 4:{clrscr();operasi();};break;
        default:{printf("\n\n\t\tSalah input!");sleep(1);goto repeat_menu;};
    }
    scanf returns in var y, an ascci value for the key pressed.
    pressing 0 on your keyboard would return in ascci value of 48, A would result in 65...
    So you have to change you switch statment to:
    Code:
    scanf("%d", &y);
    switch (x){
        case '1':start_game_easy();break;
        case '2':start_game_medium();break;
        case '3':start_game_hard();break;
        case '4':{clrscr();operasi();};break;
        default:{printf("\n\n\t\tSalah input!");sleep(1);goto repeat_menu;};
    }
    Note the commas: 1 -> '1' which now represents the ascci value of 1

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    > scanf returns in var y, an ascci value for the key pressed.
    Wrong - they're using %d, not %c
    So that part of the code is at least correct.

    However, the number of other problems are legion.
    I'm not even going to look at it until the original poster has figured out how to indent code.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    6
    opps...sorry, i'm a newbie, so, i don't know to use tag code. so sorry about that. anyway, i think you had edited the code for me, right? thanks a lot.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Posts
    6
    This is an update of my code, think i had used tag this time. So, there is an error with my score board. Is there any way to fix it. It can't update the score and save into file.
    And, is that any way i can simplify my code? Thinking that my code is rather cumbersome. Then, can anyone give some ideas to make my game more interative?

    thank you very much.


    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <dos.h>
    #include <stdlib.h>
    #include <string.h>
    #include <math.h>
    
    // GLOBAL VARIABLES
    //******************************************************************************
    int num_easy,num_medium,num_hard,num_easy2, num_medium2, num_hard2,point;
    char x,y;
    FILE *score ;
    char menu;
    char login[100], name[100],data[100];
    //******************************************************************************
    
    
    
    // PROTOTYPE FUNCTIONS
    //******************************************************************************
    int random_easy(void);
    int random_easy2(void);
    int random_medium(void);
    int random_medium2(void);
    int random_hard(void);
    int random_hard2(void);
    int campur (int num1, int num2);
    int tolak (int num1, int num2);
    int darab (int num1, int num2);
    float bahagi (float num1, float num2);
    float round (float f);
    void operasi (void);
    void start_game_easy (void);
    void start_game_medium (void);
    void start_game_hard (void);
    void menu_level (void);
    void operasi (void);
    void scoreboard ();
    void play();
    void mainmenu();
    void robot (void);
    void robot2 (void);
    void robot3 (void);
    void robot4 (void);
    void animation (void);
    //******************************************************************************
    
    
    
    // LOGIN
    //******************************************************************************
    void log()
    {   
    textcolor(RED);
    puts ("\n\n\n\n");
    printf("\t");
    cprintf ("**************************************************************");
    printf("\t\t\t\t\t");
    cprintf ("Welcome to the MATHGAME!");
    printf("\n");
    printf("\t");
    cprintf ("**************************************************************\n");
    puts ("\n\n\n\t\t\tPlease enter your name");
    printf ("\n\t\t\t>> ");
    gets(login);
    }
    //******************************************************************************
    
    
    // MAIN FUNCTION
    //******************************************************************************
    void main()
    {
    animation();
    log();
    mainmenu() ;
    }
    //******************************************************************************
    
    
    
    // MAIN MENU
    //******************************************************************************
    void mainmenu()
    {
    menu:
    clrscr();
    textcolor(RED);
    puts ("\n");
    printf("\t");
    cprintf ("**************************************************************");
    printf("\t\t\t\t\t\t");
    cprintf ("MAIN MENU");
    printf("\n");
    printf("\t");
    cprintf ("**************************************************************\n");
    printf ("\n\t\t\tWelcome %s !",login);
    score = fopen ("data.txt", "r+");
    
    while (!feof (score))
    {
    fscanf(score,"%s",&name);
    if(strcmp(login,name)==0)
    { fscanf(score,"%d",&point);
      printf ("\n\t\t\tYour previous point was %d.",point);
      break;
    }
    if (feof(score))
    puts ("\n\t\t\t<<Welcome, new player!>>");
    
    }
    puts ("\n\n\n\t\t\t1. START GAME!") ;
    puts ("\t\t\t2. Scoreboard") ;
    puts ("\t\t\t3. Quit\n") ;
    printf ("\n\n\t\t    Please enter selection... ");
    choose:
    menu=getch();
    
    switch (menu)
    {
    	case '1':  operasi();break;
       case '2':  scoreboard();break;
       case '3':  {puts ("\n\n\n\n\t\t\t<< Game ended >>");
       			  	sleep(1);
                 	exit(1);}
    
       default:  goto choose;
    }
    getch();
    }
    //******************************************************************************
    
    
    
    // RANDOMIZING EASY QUESTIONS
    //******************************************************************************
    int random_easy(void)
    {
    randomize();
    num_easy=rand()%10;
    return (num_easy);
    }
    
    int random_easy2(void)
    {
    randomize();
    num_easy2=random(10);
    return (num_easy2);
    }
    //******************************************************************************
    
    
    
    // RANDOMIZING MEDIUM QUESTIONS
    //******************************************************************************
    int random_medium(void)
    {
    
    randomize();
    num_medium=random(100)%100;
    if (num_medium<10)
    num_medium+=10;
    return (num_medium);
    }
    
    int random_medium2(void)
    {
    
    randomize();
    num_medium2=rand()%100;
    if (num_medium2<10)
    num_medium2+=10;
    return (num_medium2);
    }
    //******************************************************************************
    
    
    
    // RANDOMIZING HARD QUESTIONS
    //******************************************************************************
    int random_hard(void)
    {
    
    randomize();
    num_hard=rand()%1000;
    if (num_hard<100)
    num_hard+=100;
    return (num_hard);
    }
    
    int random_hard2(void)
    {
    randomize();
    num_hard2=random(1000);
    if (num_hard2<100)
    num_hard2+=100;
    
    return (num_hard2);
    }
    //******************************************************************************
    
    
    
    // ADDITION
    //******************************************************************************
    int campur (int num1, int num2)
    {
    int jumlah;
    if (x=='1')
    {num1=random_easy();num2=random_easy2();}
    else if (x=='2')
    {num1=random_medium();num2=random_medium2();}
    else if (x=='3')
    {num1=random_hard();num2=random_hard2();}
    
    printf(" %d + %d", num1, num2);
    jumlah=num1+num2;
    
    return (jumlah);
    }
    //******************************************************************************
    
    
    
    // SUBSTRACTION
    //******************************************************************************
    int tolak (int num1, int num2)
    {
    int jumlah;
    if (x=='1')
    {num1=random_easy();num2=random_easy2();}
    else if (x=='2')
    {num1=random_medium();num2=random_medium2();}
    else if (x=='3')
    {num1=random_hard();num2=random_hard2();}
    printf(" %d - %d", num1, num2);
    jumlah=num1-num2;
    
    return (jumlah);
    }
    //******************************************************************************
    
    
    
    // MULTIPLICATION
    //******************************************************************************
    int darab (int num1, int num2)
    {
    int jumlah;
    if (x=='1')
    {num1=random_easy();num2=random_easy2();}
    else if (x=='2')
    {num1=random_medium();num2=random_medium2();}
    else if (x=='3')
    {num1=random_hard();num2=random_hard2();}
    printf(" %d x %d", num1, num2);
    jumlah=num1*num2;
    
    return (jumlah);
    }
    //******************************************************************************
    
    
    
    // DIVISION
    //******************************************************************************
    float bahagi (float num1, float num2)
    {float jumlah;
    if (x=='1')
    {num1=random_easy();num2=random_easy2();}
    else  if (x=='2')
    {num1=random_medium();num2=random_medium2();}
    else if (x=='3')
    {num1=random_hard();num2=random_hard2();}
    printf(" %.0f / %.0f", num1,num2);
    jumlah=num1/num2;
    jumlah=round(jumlah*100)/100;
    return (jumlah);
    }
    //******************************************************************************
    
    
    
    // STARTING EASY GAME
    //******************************************************************************
    void start_game_easy (void)
    {clrscr();
    int n=1;float jumlah_game_easy;
    float answer;
    while (n<=10)
    {
    clrscr();
    textcolor(RED);
    puts ("\n");
    printf("\t");
    cprintf ("**************************************************************");
    printf("\t\t\t\t\t\t");
    if (y=='1')
    printf("ADD IT UP: ");
    else if (y=='2')
    printf("MINUS IT: ");
    else if (y=='3')
    printf("TIMES IT: ");
    else if (y=='4')
    printf("DIVIDE IT: ");
    printf ("Peanut!");
    printf("\n");
    printf("\t");
    cprintf ("**************************************************************\n");
    printf("\n\n\tAnswer these 10 questions..");
    printf("\n\n\n\tTry question no. %d :\n", n);
    puts ("\t\t\t\t--------");
    printf("\t\t\t\t");
    if (y=='1')
    jumlah_game_easy=campur(num_easy, num_easy2);
    else if (y=='2')
    jumlah_game_easy=tolak(num_easy,num_easy2);
    else if (y=='3')
    jumlah_game_easy=darab(num_easy,num_easy2);
    else if (y=='4')
    jumlah_game_easy=bahagi(num_easy,num_easy2);
    puts ("\n\t\t\t\t--------");
    if (y=='4')
    puts("\n\tHint:Give you answer in two decimal places");
    printf("\n\n\tYour answer >> ");
     scanf("%f", &answer);
     if (answer==jumlah_game_easy)
     {printf("\n\n\tWELL DONE!\n\t10 points for you!");
     point+=10;
     sleep(1);}
     else if (answer!=jumlah_game_easy)
     {printf("\n\tNope, wrong answer!");sleep(1);}
    n++;}
    printf ("\n\n\t<<Your total point is %d>>",point);
    score = fopen ("data.txt", "r+");
    fprintf (score,"%s %d",login,point);
    play();
    }
    //******************************************************************************
    
    
    
    // STARTING MEDIUM GAME
    //******************************************************************************
    void start_game_medium (void)
    {clrscr();
    int n=1;
    float answer;float jumlah_game_medium;
    while (n<=10)
    {clrscr();
    textcolor(RED);
    puts ("\n");
    printf("\t");
    cprintf ("**************************************************************");
    printf("\t\t\t\t\t\t");
    if (y=='1')
    printf("ADD IT UP: ");
    else if (y=='2')
    printf("MINUS IT: ");
    else if (y=='3')
    printf("TIMES IT: ");
    else if (y=='4')
    printf("DIVIDE IT: ");
    printf ("Piece of cake!");
    printf("\n");
    printf("\t");
    cprintf ("**************************************************************\n");
    printf("\n\n\tAnswer these 10 questions..");
    printf("\n\n\n\tTry question no. %d :\n", n);
    puts ("\t\t\t\t---------");
    printf("\t\t\t\t");
    if (y=='1')
    jumlah_game_medium=campur(num_medium, num_medium2);
    else if (y=='2')
    jumlah_game_medium=tolak(num_medium,num_medium2);
    else if (y=='3')
    jumlah_game_medium=darab(num_medium,num_medium2);
    else if (y=='4')
    jumlah_game_medium=bahagi(num_medium,num_medium2);
    puts ("\n\t\t\t\t---------");
    printf("\n\n\tYour answer >> ");
     scanf("%f", &answer);
     if (answer==jumlah_game_medium)
     {printf("\n\n\tWELL DONE!\n\t20 points for you!");
      point+=20;
      sleep(1);}
     else  if (answer!=jumlah_game_medium)
     {printf("\n\tNope, wrong answer!");sleep(1);}
    n++;}
    printf ("\n\n\t<<Your total point is %d>>",point);
    score = fopen ("data.txt", "r+");
    fprintf (score,"%s %d",login,point);
    play();
    }
    //******************************************************************************
    
    
    
    // STARTING HARD GAME
    //******************************************************************************
    void start_game_hard (void)
    {
    clrscr();
    int n;
    float answer,jumlah_game_hard;
    for (n=1;n<=10;n++)
    {clrscr();
    textcolor(RED);
    puts ("\n");
    printf("\t");
    cprintf ("**************************************************************");
    printf("\t\t\t\t\t\t");
    if (y=='1')
    printf("ADD IT UP: ");
    else if (y=='2')
    printf("MINUS IT: ");
    else if (y=='3')
    printf("TIMES IT: ");
    else if (y=='4')
    printf("DIVIDE IT: ");
    printf ("Wow!");
    printf("\n");
    printf("\t");
    cprintf ("**************************************************************\n");
    printf("\n\n\tAnswer these 10 questions..");
    printf("\n\n\n\tTry question no. %d :\n", n);
    puts ("\t\t\t\t-----------");
    printf("\t\t\t\t");
    if (y=='1')
    jumlah_game_hard=campur(num_hard, num_hard2);else
    if (y=='2')
    jumlah_game_hard=tolak(num_hard,num_hard2);else
    if (y=='3')
    jumlah_game_hard=darab(num_hard,num_hard2);else
    if (y=='4')
    jumlah_game_hard=bahagi(num_hard,num_hard2);
    puts ("\n\t\t\t\t-----------");
    printf("\n\n\tYour answer >> ");
     scanf("%f", &answer);
     if (answer==jumlah_game_hard)
     {printf("\n\n\tWELL DONE!\n\t20 points for you!");
      point+=20;
     sleep(1);}
     else if (answer!=jumlah_game_hard)
     {printf("\n\tNope, wrong answer!");sleep(1);}
    }
    printf ("\n\n\t<<Your total point is %d>>",point);
    score = fopen ("data.txt", "r+");
    fprintf (score,"%s %d",login,point);
    play();
     }
    
    //******************************************************************************
    
    
    
    // CHOOSE LEVEL
    //******************************************************************************
    void menu_level (void)
    {
    clrscr();
    textcolor(RED);
    puts ("\n");
    printf("\t");
    cprintf ("**************************************************************");
    printf("\t\t\t\t\t\t");
    cprintf ("GAME MENU");
    printf("\n");
    printf("\t");
    cprintf ("**************************************************************\n");
    puts ("\n\n\t\t    Please select level... ");
    puts ("\n\n\t\t\t1. Easy") ;
    puts ("\t\t\t2. Medium ");
    puts ("\t\t\t3. Difficult ") ;
    puts ("\n\t\t\t4. Back to Main Menu\n") ;
    printf ("\t\t\t");
    printf("\n\n\t\t   Selection:");
    repeat:
    x=getch();
    
    switch (x)
    {
    case '1':start_game_easy();
    case '2':start_game_medium();
    case '3':start_game_hard();
    case '4':operasi();
    default: goto repeat;
    }
    
    }
    //******************************************************************************
    
    
    
    // CHOOSE OPERATION
    //******************************************************************************
    void operasi (void)
    {
    clrscr();
    repeat:
    textcolor(RED);
    puts ("\n");
    printf("\t");
    cprintf ("**************************************************************");
    printf("\t\t\t\t\t\t");
    cprintf ("GAME MENU");
    printf("\n");
    printf("\t");
    cprintf ("**************************************************************\n");
    puts ("\n\n\t\t    Please select operation... ");
    puts ("\n\n\t\t\t1. Addition +") ;
    puts ("\t\t\t2. Substraction -");
    puts ("\t\t\t3. Multiplication X") ;
    puts ("\t\t\t4. Division /\n") ;
    puts ("\t\t\t5. Back to Main Menu") ;
    printf("\n\n\t\t   Selection:");
    
    game:
    y=getch();
    
    switch (y)
    {
    case '1':break;
    case '2':break;
    case '3':break;
    case '4':break;
    case '5':mainmenu();
    default: goto game;
    }
    menu_level();
    }
    //******************************************************************************
    
    
    
    // VIEW SCOREBOARD
    //******************************************************************************
    void scoreboard ()
    {
    char data[100];
    clrscr();
    textcolor(RED);
    puts ("\n");
    printf("\t");
    cprintf ("**************************************************************");
    printf("\t\t\t\t\t\t");
    cprintf ("SCOREBOARD");
    printf("\n");
    printf("\t");
    cprintf ("**************************************************************\n");
    
    score = fopen ("data.txt", "r+");
    
    if ((score=fopen("data.txt", "r+")) ==NULL)
    {puts ("\n\n\n\n\t\t\tError in reading database..");
    puts ("\n\n\n\t\t\tReturning to Main Menu..");
    sleep(2);clrscr();
    return;}
    
    puts ("\n");
    puts ("\t\tNAME\t\t\tSCORE\n");
    
    while (!feof (score))
    {
    fscanf(score,"%s",&data);
    printf ("\t\t%s",data);
    fscanf(score,"%s",&data);
    printf ("\t\t\t%s\n",data);
    }
    puts ("\n\n\n\n\n\tPress any key to return to Main Menu..");
    getch();
    clrscr();
    mainmenu();
    }
    //******************************************************************************
    
    
    
    // PLAY AGAIN?
    //******************************************************************************
    // Query to play again?
    
    void play()
    {
    char again;
    printf ("\n\n\tPlay again? (Y/N)");
    playagain:
    again=getch();
    
    if ((again=='Y')|(again=='y'))
    	operasi();
    else if ((again=='N')|(again=='n'))
    	{clrscr();puts ("\n\n\n\n\n\n\n\tThank you for playing!");
       puts ("\tHave a Nice Day!\n\n");
       sleep(2);
       exit(1);}
    else goto playagain;
    
    }
    //******************************************************************************
    
    //ROUNDING UP THE NUMBERS
    //******************************************************************************
    
    float round (float f)
    {
    return floor(f+0.5);
    }
    
    //******************************************************************************
    
    
    
    //animation
    //******************************************************************************
    
    void animation (void)
    {
    robot();sleep(3);clrscr();
    robot2();sleep(3);clrscr();
    robot3();sleep(3);clrscr();
    robot4();clrscr();
    }
    
    
    void robot (void)
    {printf("\n\n");
    printf("                       ---------       |------------------------|             \n" );
    printf("                       | o   o |     / |                        |          \n" );
    printf("                       |   v   |    /  |  Hi! I'm Math Robot!   |            \n" ) ;
    printf("                       |   ~   |   /   |                        |            \n" );
    printf("                       ---------  /    |   I'll assist you      |    \n" );
    printf("                           ||    /     |                        |  \n");
    printf("                       ---------/      |     to play the game!  |  \n");
    printf("                       |       |_ _ _ _|                        |    \n" );
    printf("                       |       |       |------------------------| \n" );
    printf("                       |       |                    \n" );
    printf("                       |       |                        \n" );
    printf("                       |       |                         \n" );
    printf("                       |-------|                       \n" );
    printf("                         | || |                            \n");
    printf("                         | || |                          \n");
    printf("                         | || |                               \n");
    printf("                         | || |                          \n");
    printf("                         |__\\\|__\\\                              \n");
    printf("                                                           \n");
    printf("                                                       \n" );
    printf("                                                             \n" );
    printf("                                                         \n");
    
    }
    
    void robot2 (void)
    {printf("\n\n");
    printf("                       ---------       |------------------------|             \n" );
    printf("                       | o   o |     / |                        |          \n" );
    printf("                       |   v   |    /  |  Before start the game,|            \n" ) ;
    printf("                       |   ~   |   /   |                        |            \n" );
    printf("                       ---------  /    |   Let me introduce     |    \n" );
    printf("                           ||    /     |                        |  \n");
    printf("                       ---------/      |     my three owners... |  \n");
    printf("                       |       |_ _ _ _|                        |    \n" );
    printf("                       |       |       |------------------------| \n" );
    printf("                       |       |                    \n" );
    printf("                       |       |                        \n" );
    printf("                       |       |                         \n" );
    printf("                       |-------|                       \n" );
    printf("                         | || |                            \n");
    printf("                         | || |                          \n");
    printf("                         | || |                               \n");
    printf("                         | || |                          \n");
    printf("                         |__\\\|__\\\                              \n");
    printf("                                                           \n");
    printf("                                                       \n" );
    printf("                                                             \n" );
    printf("                                                         \n");
    
    }
    
    void robot3 (void)
    {
    printf("\n\n");
    printf("                       ---------       |------------------------|             \n" );
    printf("                       | o   o |     / |                        |          \n" );
    printf("                       |   v   |    /  |  They are,             |            \n" ) ;
    printf("                       |   ~   |   /   |                        |            \n" );
    printf("                       ---------  /    |   1)Tew Jia Hwang      |    \n" );
    printf("                           ||    /     |   2)Kevin Munan        |  \n");
    printf("                       ---------/      |   3)Shahirman          |  \n");
    printf("                       |       |_ _ _ _|                        |    \n" );
    printf("                       |       |       |------------------------| \n" );
    printf("                       |       |                    \n" );
    printf("                       |       |                        \n" );
    printf("                       |       |                         \n" );
    printf("                       |-------|                       \n" );
    printf("                         | || |                            \n");
    printf("                         | || |                          \n");
    printf("                         | || |                               \n");
    printf("                         | || |                          \n");
    printf("                         |__\\\|__\\\                              \n");
    printf("                                                           \n");
    printf("                                                       \n" );
    printf("                                                             \n" );
    printf("                                                         \n");
    
    }
    
    void robot4 (void)
    {printf("\n\n");
    printf("                       ---------       |------------------------|             \n" );
    printf("                       | o   o |     / |                        |          \n" );
    printf("                       |   v   |    /  |  Now, you will start   |            \n" ) ;
    printf("                       |   ~   |   /   |                        |            \n" );
    printf("                       ---------  /    |    your game, hope you |    \n" );
    printf("                           ||    /     |                        |  \n");
    printf("                       ---------/      |      enjoy & good luck!|  \n");
    printf("                       |       |_ _ _ _|                        |    \n" );
    printf("                       |       |       |------------------------| \n" );
    printf("                       |       |                    \n" );
    printf("                       |       |                        \n" );
    printf("                       |       |                         \n" );
    printf("                       |-------|                       \n" );
    printf("                         | || |                            \n");
    printf("                         | || |                          \n");
    printf("                         | || |                               \n");
    printf("                         | || |                          \n");
    printf("                         |__\\\|__\\\                              \n");
    printf("                                                           \n");
    printf("                                                       \n" );
    printf("                                                             \n" );
    printf("                                                         \n");sleep(2);
    printf("\t\t\t      Please wait.\n");
    printf("\t\t\t\tLoading");
    for(int j=0;j<2;j++)
    {clreol();sleep(1);
    for(int i=0;i<3;i++)
    {printf(".");sleep(1);
    }
    printf("\b\b\b");
    }
    
    
    }
    //******************************************************************************

  7. #7
    Registered User
    Join Date
    Sep 2004
    Posts
    6
    no one could help?

  8. #8
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    I was going to help with it, but I'm in linux and you're using non-standard code (e.g. conio.h, dos.h). And your code is making my eyes bleed with the horrendous indentation method.

    If you cleaned it up and changed it to only use standard code I'm sure you'd get a lot more response.
    If you understand what you're doing, you're not learning anything.

  9. #9
    Registered User
    Join Date
    Sep 2004
    Posts
    6
    Quote Originally Posted by itsme86
    I was going to help with it, but I'm in linux and you're using non-standard code (e.g. conio.h, dos.h). And your code is making my eyes bleed with the horrendous indentation method.

    If you cleaned it up and changed it to only use standard code I'm sure you'd get a lot more response.

    i don't understand. actually i'm really a newbie. so, i'm requiring much more help from you all.
    i don't understand what you mean by standard code.i'm using borland for this c programming.

  10. #10
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    dos.h and conio.h are both non-standard header files. Meaning they don't exist in all compilers. Unless you really need them for something (you don't) then it would be best to rewrite your program to not use any features that require you to use those header files.
    If you understand what you're doing, you're not learning anything.

  11. #11
    Registered User
    Join Date
    Sep 2004
    Posts
    6
    Quote Originally Posted by itsme86
    dos.h and conio.h are both non-standard header files. Meaning they don't exist in all compilers. Unless you really need them for something (you don't) then it would be best to rewrite your program to not use any features that require you to use those header files.


    i'm using the compiler borland c++, when i search for the function sleep and exit, it requires me to include the stdlib.h and dos.h. since i'm a newbie, so, i just follow up.

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    exit is a standard function. sleep is not. You should have phrased it as:
    When I search for the function sleep, it tells me to look in dos.h, and when I search for exit, it tells me to include stdlib.h.
    stdlib.h is standard. dos.h is not. You don't need conio.h, it's just a lazy, unportable way to pause for hitting enter. (Because that's all anyone here uses it for.)

    Quzah.
    Hope is the first step on the road to disappointment.

  13. #13
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    OK, this is a one-time deal only, post any more huge masses of code without formatting and I'll delete it until you get it right.
    Plus we have better things to do that wade through masses of code. Pick a small example which focusses on your specific question. A thousand lines of non-portable poorly formatted code with "please fix it for me" is no way to go.

    Here is your code formatted - nothing more, nothing less. I'm not going to say what's wrong for the moment because I don't have the time.
    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <dos.h>
    #include <stdlib.h>
    #include <string.h>
    #include <math.h>
    
    // GLOBAL VARIABLES
    //**************************************************  ****************************
    int num_easy, num_medium, num_hard, num_easy2, num_medium2, num_hard2,
        point;
    char x, y;
    FILE *score;
    char menu;
    char login[100], name[100], data[100];
    //**************************************************  ****************************
    
    
    
    // PROTOTYPE FUNCTIONS
    //**************************************************  ****************************
    int random_easy(void);
    int random_easy2(void);
    int random_medium(void);
    int random_medium2(void);
    int random_hard(void);
    int random_hard2(void);
    int campur(int num1, int num2);
    int tolak(int num1, int num2);
    
    int darab(int num1, int num2);
    float bahagi(float num1, float num2);
    float round(float f);
    void operasi(void);
    void start_game_easy(void);
    void start_game_medium(void);
    void start_game_hard(void);
    void menu_level(void);
    void operasi(void);
    void scoreboard();
    void play();
    void mainmenu();
    void robot(void);
    void robot2(void);
    void robot3(void);
    void robot4(void);
    void animation(void);
    //**************************************************  ****************************
    
    
    
    // LOGIN
    //**************************************************  ****************************
    void log()
    {
        textcolor(RED);
        puts("\n\n\n\n");
        printf("\t");
        cprintf
            ("**************************************************  ************");
        printf("\t\t\t\t\t");
        cprintf("Welcome to the MATHGAME!");
        printf("\n");
        printf("\t");
        cprintf
            ("**************************************************  ************\n");
        puts("\n\n\n\t\t\tPlease enter your name");
        printf("\n\t\t\t>> ");
        gets(login);
    }
    
    //**************************************************  ****************************
    
    
    // MAIN FUNCTION
    //**************************************************  ****************************
    void main()
    {
        animation();
        log();
        mainmenu();
    }
    
    //**************************************************  ****************************
    
    
    
    // MAIN MENU
    //**************************************************  ****************************
    void mainmenu()
    {
      menu:
        clrscr();
        textcolor(RED);
        puts("\n");
        printf("\t");
        cprintf
            ("**************************************************  ************");
        printf("\t\t\t\t\t\t");
        cprintf("MAIN MENU");
        printf("\n");
        printf("\t");
        cprintf
            ("**************************************************  ************\n");
        printf("\n\t\t\tWelcome %s !", login);
        score = fopen("data.txt", "r+");
    
        while (!feof(score)) {
            fscanf(score, "%s", &name);
            if (strcmp(login, name) == 0) {
                fscanf(score, "%d", &point);
                printf("\n\t\t\tYour previous point was %d.", point);
                break;
            }
            if (feof(score))
                puts("\n\t\t\t<<Welcome, new player!>>");
    
        }
        puts("\n\n\n\t\t\t1. START GAME!");
        puts("\t\t\t2. Scoreboard");
        puts("\t\t\t3. Quit\n");
        printf("\n\n\t\t    Please enter selection... ");
      choose:
        menu = getch();
    
        switch (menu) {
        case '1':
            operasi();
            break;
        case '2':
            scoreboard();
            break;
        case '3':{
                puts("\n\n\n\n\t\t\t<< Game ended >>");
                sleep(1);
                exit(1);
            }
    
        default:
            goto choose;
        }
        getch();
    }
    
    //**************************************************  ****************************
    
    
    
    // RANDOMIZING EASY QUESTIONS
    //**************************************************  ****************************
    int random_easy(void)
    {
        randomize();
        num_easy = rand() % 10;
        return (num_easy);
    }
    
    int random_easy2(void)
    {
        randomize();
        num_easy2 = random(10);
        return (num_easy2);
    }
    
    //**************************************************  ****************************
    
    
    
    // RANDOMIZING MEDIUM QUESTIONS
    //**************************************************  ****************************
    int random_medium(void)
    {
    
        randomize();
        num_medium = random(100) % 100;
        if (num_medium < 10)
            num_medium += 10;
        return (num_medium);
    }
    
    int random_medium2(void)
    {
    
        randomize();
        num_medium2 = rand() % 100;
        if (num_medium2 < 10)
            num_medium2 += 10;
        return (num_medium2);
    }
    
    //**************************************************  ****************************
    
    
    
    // RANDOMIZING HARD QUESTIONS
    //**************************************************  ****************************
    int random_hard(void)
    {
    
        randomize();
        num_hard = rand() % 1000;
        if (num_hard < 100)
            num_hard += 100;
        return (num_hard);
    }
    
    int random_hard2(void)
    {
        randomize();
        num_hard2 = random(1000);
        if (num_hard2 < 100)
            num_hard2 += 100;
    
        return (num_hard2);
    }
    
    //**************************************************  ****************************
    
    
    
    // ADDITION
    //**************************************************  ****************************
    int campur(int num1, int num2)
    {
        int jumlah;
        if (x == '1') {
            num1 = random_easy();
            num2 = random_easy2();
        } else if (x == '2') {
            num1 = random_medium();
            num2 = random_medium2();
        } else if (x == '3') {
            num1 = random_hard();
            num2 = random_hard2();
        }
    
        printf(" %d + %d", num1, num2);
        jumlah = num1 + num2;
    
        return (jumlah);
    }
    
    //**************************************************  ****************************
    
    
    
    // SUBSTRACTION
    //**************************************************  ****************************
    int tolak(int num1, int num2)
    {
        int jumlah;
        if (x == '1') {
            num1 = random_easy();
            num2 = random_easy2();
        } else if (x == '2') {
            num1 = random_medium();
            num2 = random_medium2();
        } else if (x == '3') {
            num1 = random_hard();
            num2 = random_hard2();
        }
        printf(" %d - %d", num1, num2);
        jumlah = num1 - num2;
    
        return (jumlah);
    }
    
    //**************************************************  ****************************
    
    
    
    // MULTIPLICATION
    //**************************************************  ****************************
    int darab(int num1, int num2)
    {
        int jumlah;
        if (x == '1') {
            num1 = random_easy();
            num2 = random_easy2();
        } else if (x == '2') {
            num1 = random_medium();
            num2 = random_medium2();
        } else if (x == '3') {
            num1 = random_hard();
            num2 = random_hard2();
        }
        printf(" %d x %d", num1, num2);
        jumlah = num1 * num2;
    
        return (jumlah);
    }
    
    //**************************************************  ****************************
    
    
    
    // DIVISION
    //**************************************************  ****************************
    float bahagi(float num1, float num2)
    {
        float jumlah;
        if (x == '1') {
            num1 = random_easy();
            num2 = random_easy2();
        } else if (x == '2') {
            num1 = random_medium();
            num2 = random_medium2();
        } else if (x == '3') {
            num1 = random_hard();
            num2 = random_hard2();
        }
        printf(" %.0f / %.0f", num1, num2);
        jumlah = num1 / num2;
        jumlah = round(jumlah * 100) / 100;
        return (jumlah);
    }
    
    //**************************************************  ****************************
    
    
    
    // STARTING EASY GAME
    //**************************************************  ****************************
    void start_game_easy(void)
    {
        clrscr();
        int n = 1;
        float jumlah_game_easy;
        float answer;
        while (n <= 10) {
            clrscr();
            textcolor(RED);
            puts("\n");
            printf("\t");
            cprintf
                ("**************************************************  ************");
            printf("\t\t\t\t\t\t");
            if (y == '1')
                printf("ADD IT UP: ");
            else if (y == '2')
                printf("MINUS IT: ");
            else if (y == '3')
                printf("TIMES IT: ");
            else if (y == '4')
                printf("DIVIDE IT: ");
            printf("Peanut!");
            printf("\n");
            printf("\t");
            cprintf
                ("**************************************************  ************\n");
            printf("\n\n\tAnswer these 10 questions..");
            printf("\n\n\n\tTry question no. %d :\n", n);
            puts("\t\t\t\t--------");
            printf("\t\t\t\t");
            if (y == '1')
                jumlah_game_easy = campur(num_easy, num_easy2);
            else if (y == '2')
                jumlah_game_easy = tolak(num_easy, num_easy2);
            else if (y == '3')
                jumlah_game_easy = darab(num_easy, num_easy2);
            else if (y == '4')
                jumlah_game_easy = bahagi(num_easy, num_easy2);
            puts("\n\t\t\t\t--------");
            if (y == '4')
                puts("\n\tHint:Give you answer in two decimal places");
            printf("\n\n\tYour answer >> ");
            scanf("%f", &answer);
            if (answer == jumlah_game_easy) {
                printf("\n\n\tWELL DONE!\n\t10 points for you!");
                point += 10;
                sleep(1);
            } else if (answer != jumlah_game_easy) {
                printf("\n\tNope, wrong answer!");
                sleep(1);
            }
            n++;
        }
        printf("\n\n\t<<Your total point is %d>>", point);
        score = fopen("data.txt", "r+");
        fprintf(score, "%s %d", login, point);
        play();
    }
    
    //**************************************************  ****************************
    
    
    
    // STARTING MEDIUM GAME
    //**************************************************  ****************************
    void start_game_medium(void)
    {
        clrscr();
        int n = 1;
        float answer;
        float jumlah_game_medium;
        while (n <= 10) {
            clrscr();
            textcolor(RED);
            puts("\n");
            printf("\t");
            cprintf
                ("**************************************************  ************");
            printf("\t\t\t\t\t\t");
            if (y == '1')
                printf("ADD IT UP: ");
            else if (y == '2')
                printf("MINUS IT: ");
            else if (y == '3')
                printf("TIMES IT: ");
            else if (y == '4')
                printf("DIVIDE IT: ");
            printf("Piece of cake!");
            printf("\n");
            printf("\t");
            cprintf
                ("**************************************************  ************\n");
            printf("\n\n\tAnswer these 10 questions..");
            printf("\n\n\n\tTry question no. %d :\n", n);
            puts("\t\t\t\t---------");
            printf("\t\t\t\t");
            if (y == '1')
                jumlah_game_medium = campur(num_medium, num_medium2);
            else if (y == '2')
                jumlah_game_medium = tolak(num_medium, num_medium2);
            else if (y == '3')
                jumlah_game_medium = darab(num_medium, num_medium2);
            else if (y == '4')
                jumlah_game_medium = bahagi(num_medium, num_medium2);
            puts("\n\t\t\t\t---------");
            printf("\n\n\tYour answer >> ");
            scanf("%f", &answer);
            if (answer == jumlah_game_medium) {
                printf("\n\n\tWELL DONE!\n\t20 points for you!");
                point += 20;
                sleep(1);
            } else if (answer != jumlah_game_medium) {
                printf("\n\tNope, wrong answer!");
                sleep(1);
            }
            n++;
        }
        printf("\n\n\t<<Your total point is %d>>", point);
        score = fopen("data.txt", "r+");
        fprintf(score, "%s %d", login, point);
        play();
    }
    
    //**************************************************  ****************************
    
    
    
    // STARTING HARD GAME
    //**************************************************  ****************************
    void start_game_hard(void)
    {
        clrscr();
        int n;
        float answer, jumlah_game_hard;
        for (n = 1; n <= 10; n++) {
            clrscr();
            textcolor(RED);
            puts("\n");
            printf("\t");
            cprintf
                ("**************************************************  ************");
            printf("\t\t\t\t\t\t");
            if (y == '1')
                printf("ADD IT UP: ");
            else if (y == '2')
                printf("MINUS IT: ");
            else if (y == '3')
                printf("TIMES IT: ");
            else if (y == '4')
                printf("DIVIDE IT: ");
            printf("Wow!");
            printf("\n");
            printf("\t");
            cprintf
                ("**************************************************  ************\n");
            printf("\n\n\tAnswer these 10 questions..");
            printf("\n\n\n\tTry question no. %d :\n", n);
            puts("\t\t\t\t-----------");
            printf("\t\t\t\t");
            if (y == '1')
                jumlah_game_hard = campur(num_hard, num_hard2);
            else if (y == '2')
                jumlah_game_hard = tolak(num_hard, num_hard2);
            else if (y == '3')
                jumlah_game_hard = darab(num_hard, num_hard2);
            else if (y == '4')
                jumlah_game_hard = bahagi(num_hard, num_hard2);
            puts("\n\t\t\t\t-----------");
            printf("\n\n\tYour answer >> ");
            scanf("%f", &answer);
            if (answer == jumlah_game_hard) {
                printf("\n\n\tWELL DONE!\n\t20 points for you!");
                point += 20;
                sleep(1);
            } else if (answer != jumlah_game_hard) {
                printf("\n\tNope, wrong answer!");
                sleep(1);
            }
        }
        printf("\n\n\t<<Your total point is %d>>", point);
        score = fopen("data.txt", "r+");
        fprintf(score, "%s %d", login, point);
        play();
    }
    
    //**************************************************  ****************************
    
    
    
    // CHOOSE LEVEL
    //**************************************************  ****************************
    void menu_level(void)
    {
        clrscr();
        textcolor(RED);
        puts("\n");
        printf("\t");
        cprintf
            ("**************************************************  ************");
        printf("\t\t\t\t\t\t");
        cprintf("GAME MENU");
        printf("\n");
        printf("\t");
        cprintf
            ("**************************************************  ************\n");
        puts("\n\n\t\t    Please select level... ");
        puts("\n\n\t\t\t1. Easy");
        puts("\t\t\t2. Medium ");
        puts("\t\t\t3. Difficult ");
        puts("\n\t\t\t4. Back to Main Menu\n");
        printf("\t\t\t");
        printf("\n\n\t\t   Selection:");
      repeat:
        x = getch();
    
        switch (x) {
        case '1':
            start_game_easy();
        case '2':
            start_game_medium();
        case '3':
            start_game_hard();
        case '4':
            operasi();
        default:
            goto repeat;
        }
    
    }
    
    //**************************************************  ****************************
    
    
    
    // CHOOSE OPERATION
    //**************************************************  ****************************
    void operasi(void)
    {
        clrscr();
      repeat:
        textcolor(RED);
        puts("\n");
        printf("\t");
        cprintf
            ("**************************************************  ************");
        printf("\t\t\t\t\t\t");
        cprintf("GAME MENU");
        printf("\n");
        printf("\t");
        cprintf
            ("**************************************************  ************\n");
        puts("\n\n\t\t    Please select operation... ");
        puts("\n\n\t\t\t1. Addition +");
        puts("\t\t\t2. Substraction -");
        puts("\t\t\t3. Multiplication X");
        puts("\t\t\t4. Division /\n");
        puts("\t\t\t5. Back to Main Menu");
        printf("\n\n\t\t   Selection:");
    
      game:
        y = getch();
    
        switch (y) {
        case '1':
            break;
        case '2':
            break;
        case '3':
            break;
        case '4':
            break;
        case '5':
            mainmenu();
        default:
            goto game;
        }
        menu_level();
    }
    
    //**************************************************  ****************************
    
    
    
    // VIEW SCOREBOARD
    //**************************************************  ****************************
    void scoreboard()
    {
        char data[100];
        clrscr();
        textcolor(RED);
        puts("\n");
        printf("\t");
        cprintf
            ("**************************************************  ************");
        printf("\t\t\t\t\t\t");
        cprintf("SCOREBOARD");
        printf("\n");
        printf("\t");
        cprintf
            ("**************************************************  ************\n");
    
        score = fopen("data.txt", "r+");
    
        if ((score = fopen("data.txt", "r+")) == NULL) {
            puts("\n\n\n\n\t\t\tError in reading database..");
            puts("\n\n\n\t\t\tReturning to Main Menu..");
            sleep(2);
            clrscr();
            return;
        }
    
        puts("\n");
        puts("\t\tNAME\t\t\tSCORE\n");
    
        while (!feof(score)) {
            fscanf(score, "%s", &data);
            printf("\t\t%s", data);
            fscanf(score, "%s", &data);
            printf("\t\t\t%s\n", data);
        }
        puts("\n\n\n\n\n\tPress any key to return to Main Menu..");
        getch();
        clrscr();
        mainmenu();
    }
    
    //**************************************************  ****************************
    
    
    
    // PLAY AGAIN?
    //**************************************************  ****************************
    // Query to play again?
    
    void play()
    {
        char again;
        printf("\n\n\tPlay again? (Y/N)");
      playagain:
        again = getch();
    
        if ((again == 'Y') | (again == 'y'))
            operasi();
        else if ((again == 'N') | (again == 'n')) {
            clrscr();
            puts("\n\n\n\n\n\n\n\tThank you for playing!");
            puts("\tHave a Nice Day!\n\n");
            sleep(2);
            exit(1);
        } else
            goto playagain;
    
    }
    
    //**************************************************  ****************************
    
    //ROUNDING UP THE NUMBERS
    //**************************************************  ****************************
    
    float round(float f)
    {
        return floor(f + 0.5);
    }
    
    //**************************************************  ****************************
    
    
    
    //animation
    //**************************************************  ****************************
    
    void animation(void)
    {
        robot();
        sleep(3);
        clrscr();
        robot2();
        sleep(3);
        clrscr();
        robot3();
        sleep(3);
        clrscr();
        robot4();
        clrscr();
    }
    
    
    void robot(void)
    {
        // snipped due
        printf("\n\n");
    }
    
    void robot2(void)
    {
        // to them being
        printf("\n\n");
    }
    
    void robot3(void)
    {
        // unrelated to the problems at hand
        printf("\n\n");
    }
    
    void robot4(void)
    {
        printf("\n\n");
        sleep(2);
        printf("\t\t\t      Please wait.\n");
        printf("\t\t\t\tLoading");
        for (int j = 0; j < 2; j++) {
            clreol();
            sleep(1);
            for (int i = 0; i < 3; i++) {
                printf(".");
                sleep(1);
            }
            printf("\b\b\b");
        }
    }
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  14. #14
    ---
    Join Date
    May 2004
    Posts
    1,379
    uh oh,
    i see labels

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21