program asmd; uses crt; {-------------------------------------------------------------------------- program description by This program asks you what type of math you want to do, then asks for 2 numbers. Depending on what you answered to the first question, the program will either add, subtract, multiply, or divide the numbers and then print the output on the screen. You will then be asked if you want to do more math. If you do, the program will restart. USES PROCEDURES Also has added features of : 1. exponent procedure 2. ensure that the user does not divide by 0 3. program runs until the user doesn't want to continue --------------------------------------------------------------------------} VAR num1, num2, answer:real ; what, again:char ; name:string ; {-------------------------------------------------------------} procedure title; var a,b:shortint; begin gotoxy (80,25); gotoxy (17,5); for b := 1 to 3 do for a := 1 to 15 do begin textcolor (a); write ('-'); end; textcolor (green); gotoxy (33,8); write ('The Calculator'); gotoxy (33,10); textcolor(red); writeln ('By '); gotoxy (17,13); for b := 1 to 3 do for a := 1 to 15 do begin textcolor (a); write ('-'); end; gotoxy (50,20); textcolor(blue); writeln ('Press any key to Continue'); readkey; end; procedure add; begin answer := num1 + num2 end; procedure sub; begin answer := num1 - num2 end; procedure mult; begin answer := num1 + num2 end; procedure divide; begin answer := num1 / num2 end; procedure expon; var a:shortint; b : integer; begin answer := num1; b := round(num2); for a := 2 to b do answer := answer * num1; end; begin clrscr; title; clrscr; textcolor (6); write ('What''s your name? ---> '); readln (name); repeat if again = 'y' then clrscr; writeln; writeln; textcolor (green); writeln ('Ok, ',name,', what type of math do you want to do? (type only the function''s first'); writeln ('letter)'); writeln; write ('Multipy, Divide, Add, Subtract, Exponents ---> '); what := readkey; writeln; what := upcase(what); writeln; write ('Enter your first real number with no more than 2 decimal places. ---> '); readln (num1); writeln; repeat write ('Now enter your second real number with a maxium of 2 decimal places. ---> '); readln (num2); until (what <> 'D') or (num2 <> 0); writeln; writeln; writeln; textcolor (blue); case what of 'A' : add; 'S' : sub; 'M' : mult; 'D' : divide; 'E' : expon; end; case what of 'A' : what := '+'; 'S' : what := '-'; 'M' : what := '*'; 'D' : what := '/'; end; writeln (num1:0:2,' ',what,' ',num2:0:2,' = ',answer:0:2); textcolor (green); writeln; writeln; writeln; writeln ('Hey ',name,', do you want to do some more math?'); write ('Type "y" for yes or "n" for no. ---> '); again := readkey; again := upcase(again); until again = 'N'; end.