(**** Yee hsu                   ******)
(**** 4/3/2001                  ******)
(**** Various Math Equations    ******)

program math;

const
        pi = 3.141592654;
        e = 2.718281828;

var
        ans: char;
        r, count, num, Mnum, oper: integer;
        a, c, m, b, x, y, z, d, x1, x2, y1, y2, h: real;
        name, pass: string;

procedure greetings;
begin
        writeln;
        writeln('               Welcome');
        writeln;
        writeln;
        writeln('In this program you will be able to calculate the many');
        writeln('math problems you do not know how to do.');
        writeln;
        writeln('My name is Data-8 and I will be quilding you');
        writeln('along with us throughout the Net.');
        writeln;
        writeln('First, I would need to know your name.');
        writeln('Please enter your name?');
        writeln;
        write('                                 ');
        readln(name);
        writeln;
end;

procedure delta;
 procedure Mnum_1;
  procedure oper_1;
    begin
        writeln;
        writeln('You have selected the Add.');
        repeat
          writeln;
          writeln('Please enter two numbers you want to add.');
          writeln;
          readln(x, y);
          z := x + y;
          writeln;
          writeln(x : 1 : 2, ' + ', y : 1 : 2, ' = ', z : 1 : 2);
            repeat
                writeln;
                writeln('Do you want to do another one? (y/n)');
                readln(ans);

    if (ans <> 'y') and (ans <> 'n') then
      begin
        writeln;
        writeln('Invalid Input, please try again.');
      end;

        until (ans = 'y') or (ans = 'n');
      until ans = 'n';
   end;
(************************       END OF OPER_1 PROCEDURE ***************)

procedure oper_2;
begin
        writeln;
        writeln('You have selected the Subtract.');
        repeat
        writeln;
        writeln('Please enter two numbers you want to subtract.');
        writeln;
        readln(x, y);
        z := x - y;
        writeln;
        writeln(x : 1 : 2, ' - ', y : 1 : 2, ' = ', z : 1 : 2);
        repeat
        writeln;
        writeln('Do you want to do another one? (y/n)');
        readln(ans);

        if (ans <> 'y') and (ans <> 'n') then
        begin
                writeln;
                writeln('Invalid Input, please try again.');
        end;

        until (ans = 'y') or (ans = 'n');
        until ans = 'n';
    end;
(************************       END OF OPER_2   PROCEDURE       ***************)

procedure oper_3;
begin
        writeln;
        writeln('You have selected the Multiply.');
        repeat
        writeln;
        writeln('Please enter two numbers you want to muliply.');
        writeln;
        readln(x, y);
        z := x * y;
        writeln;
        writeln(x : 1 : 2, ' x ', y : 1 : 2, ' = ', z : 1 : 2);
        repeat
        writeln;
        writeln('Do you want to do another one? (y/n)');
        readln(ans);

        if (ans <> 'y') and (ans <> 'n') then
        begin
                writeln;
                writeln('Invalid Input, please try again.');
        end;

        until (ans = 'y') or (ans = 'n');
        until ans = 'n';
end;
(***********************        END OF OPER_3 PROCEDURE ************)

procedure oper_4;
begin
        writeln;
        writeln('You have selected the Divide.');
        repeat
        writeln;
        writeln('Please enter two numbers you want to divide.');
        writeln;
        readln(x, y);
        z := x / y;
        writeln;
        writeln(x : 1 : 2, ' / ', y : 1 : 2, ' = ', z : 1 : 2);
        repeat
        writeln;
        writeln('Do you want to do another one? (y/n)');
        readln(ans);

        if (ans <> 'y') and (ans <> 'n') then
        begin
                writeln;
                writeln('Invalid Input, please try again.');
        end;

        until (ans = 'y') or (ans = 'n');
        until ans = 'n';
end;
(***********************        END OF OPER_4 PROCEDURE ***************)

begin
        writeln;
        writeln('You have now logged on with Basic Math Training');
        repeat
        repeat
        writeln;
        writeln('Select the operation you want to do.');
        writeln;
        writeln('                       1       ==>     Add');
        writeln('                       2       ==>     Subtract');
        writeln('                       3       ==>     Multiply');
        writeln('                       4       ==>     Divide');
        writeln;
        write('                 ');
        readln(oper);

        if (oper < 1) or (oper > 4) then
        begin
        writeln;
        writeln('                       Invalid Input, Please try again.');
        end;

        until (oper > 0) and (oper < 5);

        case oper of
        1: 
                oper_1;
        2: 
                oper_2;
        3: 
                oper_3;
        4: 
                oper_4;
        end;

        repeat
                writeln;
                writeln('Do you want to do another operation? (y/n)');
                readln(ans);

                if (ans <> 'y') and (ans <> 'n') then
                begin
                        writeln;
                        writeln('Invalid Input, please try again.');
                end;

                until (ans = 'y') or (ans = 'n');
        until ans = 'n';
end;
(********************   END OF MNUM_1   PROCEDURE       ******************)

procedure Mnum_2;
procedure oper_1;
begin
        writeln;
        writeln('You have selected the Slope-Intercept Form.');
        repeat
        writeln;
        writeln('You may enter the slope , x , and b ');
        writeln('and I will help you find the value of y.');
        writeln;
        writeln('                       y = mx + b');
        writeln;
        writeln('Please enter the slope in decimal form.');
        writeln;
        write('                 m       =       ');
        readln(m);
        writeln;
        writeln('Please enter the value for b.');
        writeln;
        write('                 b       =       ');
        readln(b);
        writeln;
        writeln('Please enter the value for x.');
        writeln;
        write('                 x       =       ');
        readln(x);
        y := m * x + b;
        writeln;
        writeln('The value of y is ', y : 1 : 2);

        repeat
        writeln;
        writeln('Do you want to do another one? (y/n)');
        readln(ans);

        if (ans <> 'y') and (ans <> 'n') then
        begin
                writeln;
                writeln('Invalid Input, please try again.');
        end;

        until (ans = 'y') or (ans = 'n');
        until ans = 'n';
end;
(********************** END OF OPER_1 PROCEDURE ****************)

procedure oper_2;
begin
        writeln;
        writeln('You have selected the Distance Formula.');
        repeat
        writeln;
        writeln('You may enter the x1, y1, x2 , y2 ');
        writeln('and I will help you find the value of d.');
        writeln;
        writeln('Please enter the vale for x1.');
        writeln;
        write('                 x1      =       ');
        readln(x1);
        writeln;
        writeln('Please enter the value for y1.');
        writeln;
        write('                 y1      =       ');
        readln(y1);
        writeln;
        writeln('Please enter the value for x2.');
        writeln;
        write('                 x2      =       ');
        readln(x2);
        writeln;
        writeln('Please enter the value for y2.');
        writeln;
        write('                 y2      =       ');
        readln(y2);
        writeln;
        d := sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
        writeln;
        writeln('The value of d is ', d : 1 : 2);

        repeat
        writeln;
        writeln('Do you want to do another one? (y/n)');
        readln(ans);

        if (ans <> 'y') and (ans <> 'n') then
        begin
                writeln;
                writeln('Invalid Input, please try again.');
        end;

        until (ans = 'y') or (ans = 'n');
        until ans = 'n';
end;
(********************   END OF OPER_2 PROCEDURE ******************)

procedure oper_3;
begin
        writeln;
        writeln('You have selected the Phythagorean Thereom.');
        repeat
        writeln;
        writeln('You may enter the a and b value ');
        writeln('and I will help you find the value of c.');
        writeln;
        writeln('Please enter the value for a.');
        writeln;
        write('                 a       =       ');
        readln(a);
        writeln;
        writeln('Please enter the value for b.');
        writeln;
        write('                 b       =       ');
        readln(b);
        writeln;
        c := sqrt((a * a) + (b * b));
        writeln;
        writeln('The value of c is ', c : 1 : 2);

        repeat
        writeln;
        writeln('Do you want to do another one? (y/n)');
        readln(ans);

        if (ans <> 'y') and (ans <> 'n') then
        begin
                writeln;
                writeln('Invalid Input, please try again.');
        end;

        until (ans = 'y') or (ans = 'n');
        until ans = 'n';
end;
(*******************    END OF OPER_3 PROCEDURE *****************)

procedure oper_4;
begin
        writeln;
        writeln('You have selected the Quadratic Equation.');
        repeat
        writeln;
        writeln('You may enter the value for b, a, c ');
        writeln('and I will help you find the value of x1 and x2.');
        writeln;
        writeln('Please enter the value for a.');
        writeln;
        write('                 a       =       ');
        readln(a);
        writeln;
        writeln('Please enter the value for b.');
        writeln;
        write('                 b       =       ');
        readln(b);
        writeln;
        writeln('Please enter the value for c.');
        writeln;
        write('                 c       =       ');
        readln(c);
        writeln;
        x1 := ((-b) + (sqrt((b * b) - 4 * a * c))) / (2 * a);
        x2 := ((-b) - (sqrt((b * b) - 4 * a * c))) / (2 * a);
        writeln;
        writeln('The value of x1 is ', x1 : 1 : 2);
        writeln;
        writeln('The value of x2 is ', x2 : 1 : 2);

        repeat
        writeln;
        writeln('Do you want to do another one? (y/n)');
        readln(ans);

        if (ans <> 'y') and (ans <> 'n') then
        begin
                writeln;
                writeln('Invalid Input, please try again.');
        end;

        until (ans = 'y') or (ans = 'n');
        until ans = 'n';
end;
(*******************    END OF OPER_4 PROCEDURE ***************)

begin
        writeln;
        writeln('You have now logged on to Learning Algebra');
        repeat
        repeat
        writeln;
        writeln('Select the type of algebra you want to do.');
        writeln;
        writeln('       1       ==>     Slop-Intercept Form');
        writeln('       2       ==>     Distance Formula');
        writeln('       3       ==>     Pythagorean Therom');
        writeln('       4       ==>     Quadratic Equation');
        writeln;
        write('                 ');
        readln(oper);

        if (oper < 1) or (oper > 4) then
        begin
                writeln;
                writeln('Invalid Input, Please try again.');
        end;

        until (oper > 0) and (oper < 5);

        case oper of
        1: 
                oper_1;
        2: 
                oper_2;
        3: 
                oper_3;
        4: 
                oper_4
        end;

        repeat
        writeln;
        writeln('Do you want to do other algebra operations? (y/n)');
        readln(ans);

        if (ans <> 'y') and (ans <> 'n') then
        begin
                writeln;
                writeln('Invalid Input, please try again.');
        end;

        until (ans = 'y') or (ans = 'n');
        until ans = 'n';
end;
(***********************        END OF MUNM_2 PROCEDURE *************)

procedure Mnum_3;
procedure oper_1;
begin
        writeln;
        writeln('You have selected the Area for Circle.');
        repeat
        writeln;
        writeln('You may enter the value for r ');
        writeln('and I will help you find the value of A.');
        writeln;
        writeln('Please enter the value for r.');
        writeln;
        write('                 r       =       ');
        readln(r);
        a := pi * r * r;
        b := r * r;
        writeln;
        write('The Area is ', a : 1 : 2);
        writeln(' or ', b : 1 : 2, '�');

        repeat
        writeln;
        writeln('Do you want to do another one? (y/n)');
        readln(ans);

        if (ans <> 'y') and (ans <> 'n') then
        begin
                writeln;
                writeln('Invalid Input, please try again.');
        end;

        until (ans = 'y') or (ans = 'n');
        until ans = 'n';
end;
(********************** END OF OPER_1 PROCEDURE ***************)

procedure oper_2;
begin
        writeln;
        writeln('You have selected the Area for Triangle.');
        repeat
        writeln;
        writeln('You may enter the value for b and h ');
        writeln('and I will help you find the value of A.');
        writeln;
        writeln('Please enter the value for b.');
        writeln;
        write('                 b       =       ');
        readln(b);
        writeln;
        writeln('Please enter the value for h.');
        writeln;
        write('                 h       =       ');
        readln(h);
        a := (b * h) / 2;
        writeln;
        writeln('The value of A is ', a : 1 : 2);
        repeat
        writeln;
        writeln('Do you want to do another one? (y/n)');
        readln(ans);

        if (ans <> 'y') and (ans <> 'n') then
        begin
                writeln;
                writeln('Invalid Input, please try again.');
        end;

        until (ans = 'y') or (ans = 'n');
        until ans = 'n';
end;
(********************** END OF OPER_2 PROCEDURE **************)

procedure oper_3;
begin
        writeln;
        writeln('You have selected the Area for Trapezoid.');
        repeat
        writeln;
        writeln('You may enter the value for h, b1, b2');
        writeln('and I will help you find the value of A.');
        writeln;
        writeln('Please enter the value for h.');
        writeln;
        write('                 h       =       ');
        readln(h);
        writeln;
        writeln('Please enter the value for b1.');
        writeln;
        write('                 b1      =       ');
        readln(b);
        writeln;
        writeln('Please enter the value for b2.');
        writeln;
        write('                 b2      =       ');
        readln(d);
        writeln;
        a := (h * (b + d)) / 2;
        writeln;
        writeln('The value of A is ', a : 1 : 2);

        repeat
        writeln;
        writeln('Do you want to do another one? (y/n)');
        readln(ans);

        if (ans <> 'y') and (ans <> 'n') then
        begin
                writeln;
                writeln('Invalid Input, please try again.');
        end;

        until (ans = 'y') or (ans = 'n');
        until ans = 'n';
end;
(*********************  END OF OPER_3 PROCEDURE *************)

begin
        writeln;
        writeln('You have now logged on to Learning Geometry');
        repeat
        repeat
        writeln;
        writeln('Select the type of geometry you want to do.');
        writeln;
        writeln('       1       ==>     Area of Circle');
        writeln('       2       ==>     Area of Triangle');
        writeln('       3       ==>     Area of Trapezoid');
        writeln('       4       ==>     Volume of Cylinders');
        writeln;
        write('                 ');
        readln(oper);

        if (oper < 1) or (oper > 4) then
        begin
                writeln;
                writeln('Invalid Input, Please try again.');
        end;

        until (oper > 0) and (oper < 5);

        case oper of
        1: 
                oper_1;
        2: 
                oper_2;
        3: 
                oper_3;
        end;

        repeat
        writeln;
        writeln('Do you want to do other Geometry operation? (y/n)');
        readln(ans);

        if (ans <> 'y') and (ans <> 'n') then
        begin
                writeln;
                writeln('Invalid Input, please try again.');
        end;

        until (ans = 'y') or (ans = 'n');
        until ans = 'n';
end;
(************************       END OF MNUM_3 PROCEDURE **************)

procedure Mnum_4;
procedure oper_1;
begin
        writeln;
        writeln('You have selected the Sin.');
        repeat
        writeln;
        writeln('You may enter a degree and I will help you ');
        writeln('find the sin of the degree.');
        writeln;
        writeln('Please enter the degree.');
        writeln;
        write('                 degree: ');
        readln(x);
        writeln;

        z := sin(x);

        writeln('The sin of ', x : 3 : 3, ' is ', z : 3 : 8);
        writeln;

        repeat
        writeln('Do you want to do another one? (y/n)');
        readln(ans);

        if (ans <> 'y') and (ans <> 'n') then
        begin
                writeln;
                writeln('Invalid Input, please try again.');
        end;

        until (ans = 'y') or (ans = 'n');
        until ans = 'n';
end;
(***********************        END OF OPER_1 PROCEDURE *************)

procedure oper_2;
begin
        writeln;
        writeln('You have selected the Cos.');
        repeat
        writeln;
        writeln('You may enter a degree and I will help you ');
        writeln('find the cos of the degree.');
        writeln;
        writeln('Please enter the degree.');
        writeln;
        write('                 degree: ');
        readln(x);
        writeln;

        z := cos(x);

        writeln('The cos of ', x : 3 : 3, ' is ', z : 3 : 8);
        writeln;

        repeat
        writeln('Do you want to do another one? (y/n)');
        readln(ans);

        if (ans <> 'y') and (ans <> 'n') then
        begin
                writeln;
                writeln('Invalid Input, please try again.');
        end;

        until (ans = 'y') or (ans = 'n');
        until ans = 'n';
end;
(********************** END OF OPER_2 PROCEDURE ***************)

procedure oper_3;
begin
        writeln;
        writeln('Not Yet');
end;
(********************** END OF OPER_3 PROCEDURE ***************)

procedure oper_4;
begin
        writeln;
        writeln('You have selected the Properties of Triangles.');
        repeat
        writeln;
        writeln('You may enter the vaule of a, b, angle C');
        writeln('and I will help you find the value of c.');
        writeln;
        write('a = ');
        readln(a);
        write('b = ');
        readln(b);
        writeln;
        write('angle C = ');
        readln(d);
        writeln;

        c := sqrt(a * a + b * b - 2 * a * b * cos(d));

        writeln('The value of c is ', c : 2 : 3);
        writeln;

        repeat
        writeln('Do you want to do another one? (y/n)');
        readln(ans);

        if (ans <> 'y') and (ans <> 'n') then
        begin
                writeln;
                writeln('Invalid Input, please try again.');
        end;

        until (ans = 'y') or (ans = 'n');
        until ans = 'n';
end;
(********************** END OF OPER_4 PROCEDURE ***************)

begin
        writeln;
        writeln('The Trigonometry function does not work properly.');
        writeln('Do you still want to continue? (y/n)');
        readln(ans);

        if ans = 'y' then
        begin
                writeln;
                writeln('You have now logged on to Learning Trigonometry');
                repeat
                repeat
                writeln;
                writeln('Select the type of trigonometry you want to do.');
                writeln;
                writeln('1      ==>     Sin');
                writeln('2      ==>     Cos');
                writeln('3      ==>     Tan');
                writeln('4      ==>     Properties of Triangles');
                writeln;
                write('                 ');
                readln(oper);

                if (oper < 1) or (oper > 4) then
                begin
                        writeln;
                        writeln('Invalid Input, Please try again.');
                end;

                until (oper > 0) and (oper < 5);

                case oper of
                1: 
                        oper_1;
                2: 
                        oper_2;
                3: 
                        oper_3;
                4: 
                        oper_4;
                end;

        repeat
        writeln;
        writeln('Do you want to do other Trigonometry operation? (y/n)');
        readln(ans);

        if (ans <> 'y') and (ans <> 'n') then
        begin
                writeln;
                writeln('Invalid Input, please try again.');
        end;

        until (ans = 'y') or (ans = 'n');
        until ans = 'n';
                                end;
end;
(************************       END OF MUNM_4 PROCEDURE **************)

procedure credits;
begin
        writeln;
        writeln;
        writeln('Programmer:    Yee Feng Hsu');
        writeln('Language:              Pascal');
        writeln;
        writeln('All rights reserved.');
end;
(************************       END IF CREDIT PRODCEDURE        ************)

begin
        writeln;
        writeln('Hello ', name, ' Welcome to the Mathematics Solving Program.');
        repeat
        repeat
        writeln;
        writeln('Please choose the type of mathematics you want to do.');
        writeln;
        writeln('                       1       ==>     Basic Math');
        writeln('                       2       ==>     Algebra');
        writeln('                       3       ==>     Geometry');
        writeln('                       4       ==>     Trigonometry');
        writeln;
        writeln('                       5       ==>     Credits');
        writeln('                       0       ==>     Quit');
        writeln;
        write('                 ');
        readln(Mnum);

        if (Mnum < 0) or (Mnum > 5) then
        begin
                writeln;
                writeln('Invalid Input, Please try again.');
        end;

        until (Mnum >= 0) and (Mnum < 6);

        case Mnum of
        1: 
                Mnum_1;
        2: 
                Mnum_2;
        3: 
                Mnum_3;
        4: 
                Mnum_4;
        5: 
                credits;
        end;

        until Mnum = 0;
        end;

        procedure bye;
        begin
                writeln;
                writeln('Well, good-bye ', name, ', see you next time.');
        end;

begin
        showtext;
        greetings;
        delta;
        bye;
end.