#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    Norwich, UK
    Posts
    2
    Rep Power
    0

    Exclamation Maths program. Very cheeky help request...


    Hi,

    I desperately need some help! I'm currently a mature student studying computing at night school. The module that we've just finished was based primarily on programming in C, I sat the test at the end of the term unprepared and managed to somehow wangle a distinction! However, due to getting totally stumped and being swamped at the time as well, I did not complete the assignment and as such I will fail the module. I've been granted a week (until Monday 15th) to get something in.

    What I'm looking for is someone to sacrifice their ethics in return for my unending thanks! The program is relatively simple: It's a basic maths testing program. It should have a menu system asking whether one wants to answer addition, subtraction or multiplication questions (and possibly division). It should then ask a series of ten questions on the chosen subject using randomly generated numbers, and respond with a selection of positive and negative phrases (i.e. well done! or you're crap!) depending on how you answer. If you are incorrect, you should have two more chances to get it right. The program should keep a tally of the scores and when the ten questions have been answered it needs to display the number of questions passed, possibly as a percentage.

    The earliest I can get started on this will be Friday. What I am hoping (and I appreciate it's reaching a bit! :) for is either someone who is so good they can knock this up in a few minutes for me, OR someone who has done something similar to this already and doesn't mind me "borrowing" vast chunks of it, or failing that anything that could save my arse at all...!

    Mail me at fenris@pitchblack.co.uk

    Please, please, please help! Many thanks.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Posts
    0
    Rep Power
    0
    if you were to request such a program to me via email i can send you a similar progam which you can tailer to suit your needs.



    -jstn
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    Oxford, UK
    Posts
    28
    Rep Power
    0
    I would imagine something like:

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    
    int main()
    {
        int count;
        int NumberCorrect;
        int NumQuestions;
        int Operator;
        int val1, val2, result, guess;
        
        do
        {
            printf("Enter the number of questions: ");
            fflush(stdout);
            scanf("%d", &NumQuesitons);
            if(NumQuestions > 0 && NumQuestions <= 20) break;
            printf("Please enter a number between 1 and 20!\n");
        }
        while(1);
    
        do
        {
            printf("Select one of the following and press enter:\n");
            printf("  1: Addition\n");
            printf("  2: Subtraction\n");
            printf("  3: Multiplication\n");
            scanf("%d", Operator);
            if(Operator > 0 && Operator <= 3) break;
            printf("Please select an option (1, 2 or 3)!\n");
        }
        while(1);
    
        NumberCorrect = 0;
        for(count = 0; count < NumQuestions; count++)
        {
            val1 = rand() % 100;
            val2 = rand() % 100;
            printf("What is val1 ");
            if(Operator == 1) printf("+");
            else if(Operator == 2) printf("-");
            else if(Operator == 3) printf("*");
            printf(" val2?: ");
            fflush(stdout);
            scanf("%d", &guess);
            if(Operator == 1) result = val1 + val2;
            if(Operator == 2) result = val1 - val2;
            if(Operator == 3) result = val1 * val2;
            if(result == guess)
            {
                printf("Correct!\n\n");
                NumberCorrect++;
            }
            else
            {
                 prinf("Wrong!\n\n");
            }
        }
    
         printf("-- END OF TEST --\n");
         printf("Your score = %d/%d\n", NumberCorrect, NumQuestions);
    
    }
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    Norwich, UK
    Posts
    2
    Rep Power
    0

    Talking Cheers


    Huge thanks for the two of you getting back to me, I think I'm going to butcher and amalgamate the two and come out with something pretty good!

    You're both stars! Cheers again...
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    Norwich, UK
    Posts
    2
    Rep Power
    0

    Code


    Just in case any one is interested, this is the code that I came up with in the end. There was a lot more I could have done, but the tutor has told me he won't mark me any higher than a pass because it's late :( Anyway, it's done and dusted now...

    //-----------------------------------------------------------------------------|
    // Mathematics Computer Aided Learning Program |
    // |
    // Written by Fenris - April 2002 |
    //-----------------------------------------------------------------------------|

    #include <stdlib.h>
    #include <stdio.h>
    #include <time.h>
    #include <conio.h>

    void correct(int);
    void wrong(int);

    main()
    {
    char choice;
    int ran1, ran2, solution, input, ans, count, corans, countin;

    printf("\t---------------------------------------------------------------------------\n");
    printf("\t| Welcome to the Maths Computer Aided Learning Program! |\n");
    printf("\t---------------------------------------------------------------------------\n\n");

    printf("Please select an option from the menu below:\n\n");
    printf("Please enter A for addition, S for subtraction,\n");
    printf("M for multiplication or any other key to quit.\n\n\n");

    choice = getchar();

    switch(choice)
    {
    case 'a':
    case 'A': printf("\nYou selected addition.\n\n"); break;
    case 's':
    case 'S': printf("\nYou selected subtraction.\n\n"); break;
    case 'm':
    case 'M': printf("\nYou selected multiplication.\n\n"); break;
    default: printf("\nGoodbye! (Press any key to quit).");
    fflush(stdin);
    getch();
    exit (0);
    }

    corans = 0;
    for(count = 0; count < 10; count++)
    {

    // Could not get the randomize and random commands to work on this
    // compiler. This works okay though.
    srand(time(NULL));
    ran1 = 1 + (rand() % 10);
    ran2 = 1 + (rand() % 10);

    if((choice == 'a') || (choice == 'A')) solution = ran1 + ran2;
    else if((choice == 's') || (choice == 'S')) solution = ran1 - ran2;
    else if((choice == 'm') || (choice == 'M')) solution = ran1 * ran2;

    printf("What is %d ", ran1);
    if((choice == 'a') || (choice == 'A')) printf("+");
    else if((choice == 's') || (choice == 'S')) printf("-");
    else if((choice == 'm') || (choice == 'M')) printf("*");
    printf(" %d\t\t\t\t", ran2);
    scanf("%d", &input);

    if(input == solution)
    {
    corans++;
    ans = 1 + (rand() % 4);
    correct(ans);
    }
    else
    {
    ans = 1 + (rand() % 4);
    wrong(ans);
    countin = 0;
    while((countin < 2) && (input != solution))
    {
    ans = 1 + (rand() % 4);
    printf("Try again...");
    printf("\t\t\t\t");
    scanf("%d", &input);
    if(input == solution)
    {
    corans++;
    ans = 1 + (rand() % 4);
    correct(ans);
    }
    else
    {
    wrong(ans);
    countin++;
    }
    }
    }

    }

    printf("\n\t-- END OF TEST --\n\n");
    printf("You scored = %d out of 10\n\n", corans);
    if (corans > 7) printf("Well done, you passed!\n");
    else printf("You really are thick. Go and shoot yourself.\n");
    printf("\nPress any key to continue");
    fflush(stdin);
    getch();

    return 0;
    }

    //------------------------------------------------------------------------------
    void correct(ans)
    {
    switch(ans)
    {
    case 1:
    printf("\nVery good!\n\n");
    break;
    case 2:
    printf("\nNice one!\n\n");
    break;
    case 3:
    printf("\nHurrah!\n\n");
    break;
    case 4:
    printf("\nKeep up the good work!\n\n");
    }
    }
    //------------------------------------------------------------------------------
    void wrong(ans)
    {
    switch(ans)
    {
    case 1:
    printf("\nNo, idiot!\n\n");
    break;
    case 2:
    printf("\nAre your parents brother and sister?\n\n");
    break;
    case 3:
    printf("\nRetard!\n\n");
    break;
    case 4:
    printf("\nAre you stupid?\n\n");
    }
    }

IMN logo majestic logo threadwatch logo seochat tools logo