TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: CLIFF RHODES
from: FRANK MASINGILL
date: 1997-08-23 22:28:00
subject: MATHPLAY.CPP

        Cliff, here is the program after I made the changes you
suggested.  I do hope to develop it into a full-fledged C++ with
some object-oriented features and I'm studying all of the examples I
can find in my books and disks.  I started this as a project for the
kids next door to play with when we keep them and wanted to get it
to the point where they could play with it.
        I am, as you suggested, looking at the four math routines.
In addition to making the changes you told me about I also changed
the color scheme so that, e.g., if the kid calls the Multiplication
part it will come up in exactly the colors of the line chose in the
menu.  I hope to dress that up in time as well.  
        Thanks to you it's in good shape for them to play with now
and I can begin seeing how some class might be put in it.  As you
saw, I also had a message from Jerry Coffin with some suggestions
along that line.  
        So here it is as you and Kurt Kuzba steered me.  In time
I'll certainly take out that mixture of C and C++.  I have been
interested in preserving the color.  Also, I know I'll eventually
put the prototypes, etc., in a header file.  
MATHPLAY.CPP:
#include 
#include 
#include 
#include 
#include               // for exit statement
int num1, num2, guess, ans ;
addCalc();
minusCalc();
multCalc();
divCalc();
void promptc(int x, int y, int color , const char *p);
int menu();
main()
{
	int col;
	while (menu())
	 ;
	 clrscr();
	 gotoxy(col,12);
	 textcolor(11);
	 cputs("Thanks for playing");
	return 0;
}
int menu()
{
   int i, col ;
   col=30;
   clrscr();
   promptc(col, 10, 14, "Would you like to practice a little");
   col=35;
   promptc(col, 12, 14, "1. Addition?");
   promptc(col, 13, 10, "2. Subtraction?");
   promptc(col, 14, 13, "3. Multiplication?");
   promptc(col, 15, 11, "4. Division?");
   promptc(col, 16, 12, "5. or just Quit?");
   do
   {
		gotoxy(col,20);
		textcolor(15);
		cputs("Enter your choice: ");
		scanf("%d", &i);
		switch(i)
		{
			 case 1: addCalc();    break;
			 case 2: minusCalc();    break;
			 case 3: multCalc();   break;
			 case 4: divCalc();    break;
			 case 5: break;
		}
   }while (i  5);
   return (i == 5) ? 0 : 1;
}
addCalc()
{
	  clrscr();
	  int col=20;
	  gotoxy(col, 10);
	  textcolor(14);
	  cputs("ADDITION PROBLEM:");
	  gotoxy(col, 12);
	  cputs("Type in the first number (Addend)? ");
	  cin >> num1;
	  gotoxy(col, 13);
	  cputs("Type in the second number (Addend)? ");
	  cin >> num2;
	  ans = num1 + num2;
	  gotoxy(col, 14);
	  cputs("What do you think is the answer (called the SUM)? ");
	  cin >> guess;
	  gotoxy(col, 15);
      cprintf("The answer is ");
      textcolor(15);
      cprintf("%d", ans);
      textcolor(2);
      gotoxy(col, 16);
      cprintf("You guessed %s", (ans == guess) ? "right!" : "wrong.");
	  cout << endl;
      gotoxy(col, 18);
      cprintf("Would you like to try another (Y/N)? ");
      do {
         guess = (0 == (guess = getch())) ? -getch() : guess;
         guess = toupper(guess);
      }  while(guess != 'Y' && guess != 'N');
      textcolor(14);
      gotoxy(col,22);
      cprintf("Press any key");
      getch();
      return 0;
}
minusCalc()
{
      clrscr();
      int col=20;
      gotoxy(col, 10);
      textcolor(10);
      cputs("SUBTRACTION PROBLEM:");
      gotoxy(col, 12);
      cputs("Type in the Minuend (number to subract FROM: ");
      cin >> num1;
      gotoxy(col, 13);
      cputs("Now, type in the Subtrahend (number to subract: ");
	  cin >> num2;
      ans = num1 - num2;
      gotoxy(col, 14);
      cputs("What do you think is the answer (REMAINDER)? ");
      cin >> guess;
      gotoxy(col, 15);
      cprintf("The answer is ");
      textcolor(15);
      cprintf("%d", ans);
      textcolor(10);
      gotoxy(col, 16);
      cprintf("You guessed %s", (ans == guess) ? "right!" : "wrong.");
      cout << endl;
	  gotoxy(col, 18);
      cprintf("Would you like to try another (Y/N)? ");
      do {
         guess = (0 == (guess = getch())) ? -getch() : guess;
         guess = toupper(guess);
      }  while(guess != 'Y' && guess != 'N');
      textcolor(10);
      gotoxy(col,22);
      cprintf("Press any key");
      getch();
      return 0;
}
multCalc()
{
	  clrscr();
	  int col=20;
	  gotoxy(col, 10);
	  textcolor(13);
	  cputs("MULTIPLICATION PROBLEM:");
	  gotoxy(col, 12);
	  cputs("Type in the number to be multiplied (MULTIPLICAND): ");
	  cin >> num1;
	  gotoxy(col, 13);
	  cputs("Type in the number to multiply it by (MULTIPLIER): ");
	  cin >> num2;
	  ans = num1 * num2;
	  gotoxy(col, 14);
	  cputs("What do you think is the answer (PRODUCT)? ");
	  cin >> guess;
	  gotoxy(col, 15);
	  cprintf("The answer is ");
	  textcolor(15);
	  cprintf("%d", ans);
	  textcolor(13);
	  gotoxy(col, 16);
	  cprintf("You guessed %s", (ans == guess) ? "right!" : "wrong.");
	  cout << endl;
	  gotoxy(col, 18);
	  cprintf("Would you like to try another (Y/N)? ");
	  do {
		 guess = (0 == (guess = getch())) ? -getch() : guess;
		 guess = toupper(guess);
	  }  while(guess != 'Y' && guess != 'N');
	  textcolor(13);
	  gotoxy(col,22);
	  cprintf("Press any key");
	  getch();
	  return 0;
}
divCalc()
{
	  clrscr();
	  int col=20;
	  gotoxy(col, 10);
	  textcolor(11);
	  cputs("DIVISION PROBLEM:");
	  gotoxy(col, 12);
	  cputs("Type in the number to be divided (DIVIDEND): ");
	  cin >> num1;
	  gotoxy(col, 13);
	  cputs("Type in the number to divide it by (DIVISOR): ");
	  cin >> num2;
	  ans = num1 / num2;
	  gotoxy(col,14);
	  cputs("What do you think is the answer (QUOTIENT): ");
	  cin >> guess;
	  gotoxy(col, 15);
	  cprintf("The answer is ");
	  textcolor(15);
	  cprintf("%d", ans);
	  textcolor(11);
	  gotoxy(col, 16);
	  cprintf("You guessed %s", (ans == guess) ? "right!" : "wrong.");
	  cout << endl;
	  gotoxy(col, 18);
	  cprintf("Would you like to try another (Y/N)? ");
	  do {
		 guess = (0 == (guess = getch())) ? -getch() : guess;
		 guess = toupper(guess);
	  }  while(guess != 'Y' && guess != 'N');
	  textcolor(11);
	  gotoxy(col,22);
      cprintf("Press any key");
      getch();
      return 0;
}
void promptc(int x, int y, int color, const char *p)
{
	gotoxy(x,y);
	textcolor(color);
    cputs(p);
}
--------------------------------END CODE----------------------------
Sincerely, 
                                     Frank
                                                                              
                                                       
--- PPoint 2.03
---------------
* Origin: Maybe in 5,000 years - frankmas@juno.com (1:396/45.12)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.