0

I am trying to code a math tutor program that will have random numbers generated. Any suggestions would be greatful.

Output suppose to be:
I am having problems with this code. I keep switching it around and can not seem to get it right. This is what output suppose to be:

Menu of Operations
1. Addition
2. Subtraction
3. Multiplication
4. Quit.

Enter the number of the operation to try (1-4)? 2

What is 6 - 8 ? 2
No, the correct answer is: -2


Menu of Operations
1. Addition
2. Subtraction
3. Multiplication
4. Quit.

Enter the number of the operation to try (1-4)? 3
What is 3 x 4 ? 12
Yes, that is correct. Good job!
Menu of Operations
1. Addition
2. Subtraction
3. Multiplication
4. Quit.

Enter the number of the operation to try (1-4)? 6
(BEEP) Input value is out of range.
Enter the number of the operation to try (1-4)? 4
Program Complete

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


#define SENT 4 //"Quit" menu choice


/*  Function Prototypes */


    void DisplayMenu (void);
    void GetMenuChoice (void);
    void Gen2Rand (int*r1, int*r2);
    void DrillOneProb (int*c, int*r1, int*r2);





/*============Mainline Procedures===============*/

int main (void);

    int       c;   //Menu Choice (1-4)
    int   r1,  //First Random Integer:  2-12 inclusive
          r2;  //Second Randon Integer:  2-12 inclusive




/*===========CHILD FUNCTIONS===============*/

/*  Display Title and Menu */

void DisplayMenu (void)

{
        printf("MENU OF OPERATIONS\n");
        printf("1. Addition.\n");
        printf("2. Subtraction.\n");
        printf("3. Multiplication.\n");
        printf("4. Quit.\n\n");


}

/* Get Menu Choice */

void GetMenuChoice (void)

    {
        int c;
        printf ("Enter the number of the operation to try (1-4):\n");
        scanf ("%d", &c);
        while
             (c<1 || c>SENT)
                printf("\aInput value is out of range.\n");


    }

/* Generate and return 2 integers between 2-12 inclusive */

void Gen2Rand (int *r1p, int *r2p)

    {
        int c;
        c=0;

        if (c>=1 && c<SENT)

        int r1; //First random number
        int r2; //Second random number

        r1 = 2 + rand() %11;
        r2 = 2 + rand() %11;

       *r1p = r1;
       *r2p = r2;

       printf("Program complete\n");

    }

/* Display two random numbers and ask user what the answer would be after the chosen operation*/

void DrillOneProb (int*c, int*r1, int*r2)

{
        int CorAns, //Correct Answer
            Reply;  // Users Reply


            printf("\nWhat is %d",*r1);
            scanf("%d", r1);

            *r1=2 + rand () % 11;



    switch (c)

    {
        case '1':
              printf("+");
               CorAns = *r1 + *r2;

          break;


        case '2':
               printf("-");
              CorAns = r1 - r2;
          break;


        case '3':
          printf("x");
          CorAns = r1 * r2;
          break;

}

    printf("%d ?  %d\n", r2, Reply);

   if
          Reply == CorAns
               {
               printf("Yes, that is correct. Good Job!");
            }

        else
            {    printf("No, the correct answer is: %d", CorAns);
                printf("\n\n");
            }
return (0);

}

Edited by katbury: n/a

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by melepuram
0

There are problems with the main().
First there should be no semicolon after int main(void).
Secondly, you must ecnlose the text of the main() with curly braces {}.

0

There are problems with the main().
First there should be no semicolon after int main(void).
Secondly, you must ecnlose the text of the main() with curly braces {}.

I already changed that, I ran my compiler and am having some problems with my switch case. The brace afterwards is coming up with error illegal type ointer to int in switch. Also the Reply = CorAns is coming up with found 'Reply' expected (.

Can anyone look at this part and tell me what is wrong.

0

Line 127 must be enclosed in parentheses. I'd combine lines 126 and 127 into the following

if(Reply == CorAns)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.