I updated my program and have fixed most problems. I have a problem with the pointer, which I cannot get fixed.
Code:
#include <stdio.h>
#include <stdlib.h>
#define SENT 4 //"Quit" menu choice
/* Function Prototypes */
void DisplayMenu (void);
int 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
DisplayMenu();
c = GetMenuChoice();
while (c >= 1 && c < SENT)
{ Gen2Rand (&r1, &r2);
DrillOneProb (c, r1,r2);
DisplayMenu();
c = GetMenuChoice();
printf("Program Complete\n");}
return (0);
}
/*===========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 */
int GetMenuChoice (void)
{
int c;
do{
printf ("Enter the number of the operation to try (1-4):\n");
scanf ("%d", &c);
if (c<1 || c>SENT)
printf("\aInput value is out of range.\n");
while (c < 1 || c > SENT);
return (c);
}
/* Generate and return 2 integers between 2-12 inclusive */
void Gen2Rand (int*r1p, int*r2p)
int r1; //First random number
int r2; //Second random number
r1 = 2 + rand() % 11;
r2 = 2 + rand() % 11;
*r1p = r1;
*r2p = r2;
return (0);
}
/* 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
switch (c)
{
case 1:
printf("+");
CorAns = r1 + r2;
break;
case 2:
printf("-");
CorAns = r1 - r2;
break;
default:
printf("x");
CorAns = r1 * r2;
break;
}
printf(" %d, ?", Reply);
scanf ("%d", &Reply);
if
(Reply == CorAns)
printf("Yes, that is correct. Good Job!");
else
{ printf("No, the correct answer is: %d", CorAns);
printf("\n\n");
}
}