Thread: urgent need hlp..i'm develop a math quiz program thy was several error

  1. #16
    Registered User
    Join Date
    Sep 2014
    Posts
    364
    Quote Originally Posted by algorism View Post
    Quote Originally Posted by Horror View Post
    For input streams, fflush() discards any buffered data that has been fetched from the underlying file, but has not been consumed by the application.
    You pulled that out of your ass. Windows works that way, but linux doesn't.
    The quoted line from Horror is from the fflush man-page of linux.
    But this doesn't mean stdin, because stdin have no input buffer.
    That was Horror assume as input buffer is in real the output buffer from the console.
    The example from algorism show that.
    I have tested it with files that was opened for reading, but nothing changes.
    I think, this means buffers from network connections or serial line.
    Last edited by WoodSTokk; 07-26-2017 at 08:49 AM.
    Other have classes, we are class

  2. #17
    Registered User
    Join Date
    Jul 2017
    Posts
    48

    thank u guy for helping me...i gt last question now

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    #include<time.h>
    #pragma warning(disable:4996)
    
    
    int menu();
    void additionmenu();
    void subtractionmenu();
    void multiplicationmenu();
    void addEasy();
    void addMedium();
    void addDifficult();
    
    
    int main()
    {
        int choice = menu();
        printf("You have selected the choice %d", choice);
    
    
        if (choice == 1)
        {
            printf("You have selected addition\n");
            additionmenu();
        }
        else if (choice == 2)
        {
            printf("You have selected subtraction\n");
            subtractionmenu();
        }
        else if (choice == 3)
        {
            printf("You have selected multiplication\n");
            multiplicationmenu();
        }
        else
        {
            printf("Invalid choice\n");
        }
        system("pause");
    }
    
    
    int menu()
    {
        int choice;
        printf("1.addition\n");
        printf("2.subtraction\n");
        printf("3.multiplication\n");
        printf("Please choose either 1,2 or 3:\n");
        scanf("%d", &choice);
        (getchar() != '\n');
        return choice;
    }
    
    
    void additionmenu()
    {
        char choice;
        printf("Please select the level\n");
        printf("A level 1\n");
        printf("B level 2\n");
        printf("C level 3\n");
        scanf("%c", &choice);
        if (choice == 'A' || choice == 'a')
        {
            printf("You have selected level 1\n");
            addEasy();
        }
        else if (choice == 'B' || choice == 'b')
        {
            printf("You have selected level 2\n");
            addMedium();
        }
        else if (choice == 'C' || choice == 'c')
        {
            printf("You have selected level 3\n");
            addDifficult();
        }
        else
        {
            printf("Invalid choice\n");
    
    
        }
    }
    
    
    
    
    void subtractionmenu() {
        printf("To Do\n");
    }
    
    
    void multiplicationmenu() {
        printf("To Do\n");
    }
    
    
    void addEasy() {
        
        
        
    
    
            int n1, n2, pcans, userans;
            int count = 1, mark = 0;
            char choice;
            printf("Welcome to addition level 1\n");
    
    
            do {
                srand((unsigned int)time(NULL));
                n1 = rand() % 10;
                n2 = rand() % 10;
                pcans = n1 + n2;
    
    
                printf("%d.%d+%d>", count, n1, n2);
                scanf("%d", &userans);
                if
                    (userans == pcans) {
                    printf("You are right\n");
                    mark = mark + 10;
                }
                else
                {
                    printf("You are wrong\n");
                }
                count++;
            } while (count <= 10);
            system("pause");
            system("cls");
            printf("Your score is %d", mark);
            rewind(stdin);
            if (mark >= 80)
            {
                printf("Congratulation!!! you pass level1!!\n");
                printf("Do you want move to next level?(Y/N)\n");
                scanf("%c", &choice);
                switch (choice)
                {
                case'Y':
                case'y': {printf("addMedium)()");
                    break; }
                case'N':
                case'n': {system("exit");
                    break; }
                default:
                {     printf("Invalid!!\n");
                printf("You are back to main menu.\n");
                system("pause");
                additionmenu();
                }
                }
    
    
    
    
    
    
            }
    
    
            void addMedium(); {
                printf("That's a bit harder\n");
            }
    
    
            void addDifficult(); {
                printf("That's really tricky\n");
            }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
        }


    can someone help me....it show error at line 1 unresolved external symbol _addMedium referenced in function _additionmenu

  3. #18
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Two problems:
    Code:
    ...
            void addMedium(); {
                printf("That's a bit harder\n");
            }
    
    
            void addDifficult(); {
                printf("That's really tricky\n");
            }
    
        }  // Close of addEasy()
    1) You define both these functions inside addEasy(). You cannot define a function inside another function!

    2) Note the semicolons between the closing paren, and the opening curly brace for both functions! They should not be there!
    Last edited by rstanley; 07-27-2017 at 08:56 AM.

  4. #19
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Code:
            void addMedium(); {  //!! what's this ; doing?
                printf("That's a bit harder\n");
            }
     
     
            void addDifficult(); {  //!! what's this ; doing?
                printf("That's really tricky\n");
            }
    Your indentation is poor, it's hard to see where addEasy() actually ends.
    Indent style - Wikipedia
    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.

  5. #20
    Registered User
    Join Date
    Jul 2017
    Posts
    48
    Code:
             #include<stdio.h>#include<stdlib.h>
    #include<math.h>
    #include<time.h>
    #pragma warning(disable:4996)
    
    
    int menu();
    void additionmenu();
    void subtractionmenu();
    void multiplicationmenu();
    void addEasy();
    void addMedium();
    void addDifficult();
    
    
    int main()
    {
        int choice = menu();
        printf("You have selected the choice %d", choice);
    
    
        if (choice == 1)
        {
            printf("You have selected addition\n");
            additionmenu();
        }
        else if (choice == 2)
        {
            printf("You have selected subtraction\n");
            subtractionmenu();
        }
        else if (choice == 3)
        {
            printf("You have selected multiplication\n");
            multiplicationmenu();
        }
        else
        {
            printf("Invalid choice\n");
        }
        system("pause");
    }
    
    
    int menu()
    {
        int choice;
        printf("1.addition\n");
        printf("2.subtraction\n");
        printf("3.multiplication\n");
        printf("Please choose either 1,2 or 3:\n");
        scanf("%d", &choice);
        (getchar() != '\n');
        return choice;
    }
    
    
    void additionmenu()
    {
        char choice;
        printf("Please select the level\n");
        printf("A level 1\n");
        printf("B level 2\n");
        printf("C level 3\n");
        scanf("%c", &choice);
        if (choice == 'A' || choice == 'a')
        {
            printf("You have selected level 1\n");
            addEasy();
        }
        else if (choice == 'B' || choice == 'b')
        {
            printf("You have selected level 2\n");
            addMedium();
        }
        else if (choice == 'C' || choice == 'c')
        {
            printf("You have selected level 3\n");
            addDifficult();
        }
        else
        {
            printf("Invalid choice\n");
    
    
        }
    }
    
    
    
    
    void subtractionmenu() {
        printf("To Do\n");
    }
    
    
    void multiplicationmenu() {
        printf("To Do\n");
    }
    
    
    void addEasy() {
    
    
    
    
    
    
    
    
        int n1, n2, pcans, userans;
        int count = 1, mark = 0;
        char choice;
        printf("Welcome to addition level 1\n");
    
    
        do {
            srand((unsigned int)time(NULL));
            n1 = rand() % 10;
            n2 = rand() % 10;
            pcans = n1 + n2;
    
    
            printf("%d.%d+%d>", count, n1, n2);
            scanf("%d", &userans);
            if
                (userans == pcans) {
                printf("You are right\n");
                mark = mark + 10;
            }
            else
            {
                printf("You are wrong\n");
            }
            count++;
        } while (count <= 10);
        system("pause");
        system("cls");
        printf("Your score is %d", mark);
        rewind(stdin);
        if (mark >= 80)
        {
            printf("Congratulation!!! you pass level1!!\n");
            printf("Do you want move to next level?(Y/N)\n");
            scanf("%c", &choice);
            switch (choice)
            {
            case'Y':
            case'y': {printf("addMedium)()");
                break; }
            case'N':
            case'n': {system("exit");
                break; }
            default:
            {     printf("Invalid!!\n");
            printf("You are back to main menu.\n");
            system("pause");
            additionmenu();
            }
            }
    
    
    
    
    
    
        }
    so this should be like this right?
    Last edited by kkkcj; 07-27-2017 at 09:26 AM.

  6. #21
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Did you compile it with the highest warning level? Did you see any warnings or errors after compiling? Did you attempt to run it after compiling? Would this answer your question?

    If so, you would know you have just deleted the two function definitions, rather than moving them outside the other function, and simply removing the two semicolons.

    EDIT: Also, please remove all the extraneous blank lines from the code. One line rather than 10 will do the job.

    EDIT2: PLEASE remove the following line from your code!!! YOU WANT to see ALL warnings and errors!!!
    Code:
    #pragma warning(disable:4996)
    Last edited by rstanley; 07-27-2017 at 09:38 AM.

  7. #22
    Registered User
    Join Date
    Jul 2017
    Posts
    48
    when run it ,it show two error which is the left brace '{' was unmatched at the end of the file and character represented by universal-character-name '\uFF01' cannot be represented in the current code page this two

  8. #23
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Turn OFF the pragma line!!! Turn ON and turn UP the warning levels to the highest level!!!

    Replace the missing closing brace at the end of the file! "}"

    Replace the two function definitions that you deleted!!!

    Recompile and READ the warnings and error messages!!!

  9. #24
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Quote Originally Posted by rstanley View Post
    Turn OFF the pragma line!!!
    I believe that pragma stops the windows compiler from complaining about scanf (which should be replaced with scanf_s for better security).

    Also, srand is obviously in the wrong place.

  10. #25
    Registered User
    Join Date
    Jul 2017
    Posts
    48
    as you say pragma is use to stop the windows compiler from complaining about scanf ,and u say srand in wrong place? can u tell me which line should i put the srand?

  11. #26
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    I thought that the pragma might have been hiding other warnings. Perhaps you should switch from scanf() to scanf_s() and remove the pragma.

    I haven't used a Windows compiler for longer than I care to admit. Linux, gcc and clang only.

    You should move the srand() line to the first statement in main(). Only needs to be executed once for the entire program.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Math Quiz Program Help
    By HystericalFool in forum C Programming
    Replies: 5
    Last Post: 11-17-2014, 12:00 AM
  2. IDE or compilier to develop c program in windows
    By sharonch in forum Windows Programming
    Replies: 1
    Last Post: 11-09-2012, 02:40 AM
  3. Replies: 1
    Last Post: 11-21-2011, 08:27 AM
  4. making a math quiz program
    By mackieinva in forum C Programming
    Replies: 10
    Last Post: 09-17-2007, 03:38 PM
  5. I'm Requested to develop a C program
    By BadProgrammer in forum C Programming
    Replies: 16
    Last Post: 05-18-2003, 12:10 AM

Tags for this Thread