Return-Path: <ciortiz@MIT.EDU>
Received: from grand-central-station.mit.edu by po11.mit.edu (8.9.2/4.7) id CAA26070; Wed, 17 Jul 2002 02:32:11 -0400 (EDT)
Received: from manawatu-mail-centre.mit.edu (MANAWATU-MAIL-CENTRE.MIT.EDU [18.7.7.71])
	by grand-central-station.mit.edu (8.9.2/8.9.2) with ESMTP id CAA22902
	for <sipb@MIT.EDU>; Wed, 17 Jul 2002 02:31:18 -0400 (EDT)
Received: from quickstation-westgate.mit.edu (QUICKSTATION-WESTGATE.MIT.EDU [18.98.1.233])
	by manawatu-mail-centre.mit.edu (8.9.2/8.9.2) with ESMTP id CAA17056
	for <sipb@mit.edu>; Wed, 17 Jul 2002 02:31:18 -0400 (EDT)
Received: (from ciortiz@localhost) by quickstation-westgate.mit.edu (8.9.3)
	id CAA02907; Wed, 17 Jul 2002 02:31:17 -0400 (EDT)
Message-Id: <200207170631.CAA02907@quickstation-westgate.mit.edu>
To: sipb@MIT.EDU
Subject: my code (madmath1.cpp)
Date: Wed, 17 Jul 2002 02:31:17 -0400
From: Carlos I Ortiz <ciortiz@MIT.EDU>


#include <iostream.h>
#include <stdlib.h>
#include <time.h>

using namespace std;

short oper, a, b, c, d;
short n=0; short e=0;
clock_t start, end;

void addt(short& x,short& y,short& z)
{
  z = x + y;
  cout << "\t" << x;
  cout << "\n+\t" << y;
}

void subt(short& x,short& y,short& z)
{
  z = x - y;
  cout << "\t" << x;
  cout << "\n-\t" << y;
}

void mult(short& x,short& y,short& z)
{
  z = x * y;
  cout << "\t" << x;
  cout << "\nx\t" << y;
}

void divt(short& x,short& y,short& z)
{
  z = x * y;
  short temp = z;
  z = y;
  y = x;
  x = temp;
  cout << char(9) << x;
  cout << "\n\%\t" << y;
}

void main()
{
  cout << "\n\nHow are you doing today? What is your first name?\n>";
  char name[10] = {0};
  cin >> name;
  cout << "\n\nHey " << name << ", we are going to do some mad math 
drilling today.\n";
  cout << "Are you up to it? I thought so, so let's get on with it !! :o)";
  cout << "\n\nThis program will practice quick 1 digit adding, 
subtracting,\n";
  cout << "multiplying, and dividing. Do you want to practice any one of 
them\n";
  cout << "in particular, or you want to try all at random? Choose:\n";
  cout << "0 for random\n";
  cout << "1 for adding\n";
  cout << "2 for subtracting\n";
  cout << "3 for multiplying\n";
  cout << "4 for dividing";
  cout << "\n>";
  short choice; cin >> choice;
  cout << "\nOk then - Good luck ...";
  cout << "\n\nRemember to enter 999 at any time to quit.";
  start = clock();
  do
  {
   srand(n);
   if (choice==0) oper = rand()/4;
   else oper = choice - 1;
   a = rand()/10;
   b = rand()/10;
   c = 0;
   cout << "\n\n";
   if (oper%4==0) addt(a,b,c);
   else if (oper%4==1) subt(a,b,c);
   else if (oper%4==2) mult(a,b,c);
   else if (oper%4==3 && a !=0) divt(a,b,c);
   else continue;
   cout << "\n__________";
   do
   {
    cout << "\n\t";
    cin >> d;
    if (d==999) break;
    else if (d != c) e++;
   }
   while (d != c);
   n++;
  }
  while (d !=999);

  end = clock();
  cout << "\n\nThanx for practicing, " << name << ". Here are your stats 
for the session:";
  cout << "\n\nProblems:\t" << n;
  cout << "\n\nMistakes:\t" << e;
  cout << "\n\nTotal Time:\t";
  clock_t sect = (end-start)/CLK_TCK;
  int secs = int(sect);
  int mins = secs/60;
  secs %= 60;
  cout << mins << " mins : " << secs << " secs.";
  cout << "\n\ngoodbye :p\n\n";
}
