Beginner Pascal help - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Beginner Pascal help

MiddleMiddle Posts: 6Member
I am studying computing at A-level so i have to use Pascal

I am very new to this, this is what i have so far:

[code]PROGRAM Calculator;
USES
CRT, SYSUTILS;
VAR
Number1, Number2, Operation, Answer :LONGINT;

PROCEDURE Welcome;
BEGIN
WRITELN('Welcome to my calculator that i have programmed in pascal');
WRITELN('First you must choose two numbers to work with');
END;

PROCEDURE Obtain;
BEGIN
WRITE('Enter first number: ');
READLN(Number1);
WRITE('Enter second number: ');
READlN(Number2);
END;

PROCEDURE Obtainoperation;
BEGIN
WRITELN('What do you want to do with these numbers? [Enter *, /, + or -]');
READLN(Operation);
END;

PROCEDURE Add;
BEGIN
Answer:=Number1 + Number2;
END; Addition

PROCEDURE Divide;
BEGIN
Answer:=Number1 / Number2;
END;

PROCEDURE Multiply;
BEGIN
Answer:=Number1 * Number2;
END;

PROCEDURE Subtract;
BEGIN
Answer:=Number1 - Number2;

PROCEDURE Display;
BEGIN
WRITE('Total is: ');
WRITELN(Answer);
END;

BEGIN
Welcome;
Obtain;
Obtainoperation;
***not sure what to put here, i want "If Operation is X do Y procedure"
Display;
READLN;
END.

[/code]


Couple of questions:
1. What do i put where i have the asterisk
2. When i try running as is i get: "Error 26: Type mismatch" at this point:

[code]PROCEDURE Divide;
BEGIN
Answer:=Number1 / Number2; *here
END;[/code]

Comments

  • quikcarlquikcarl Posts: 59Member
    Great start for a beginning program! As for your
    what to do at the ***, try a case statement.
    [code] case Obtainoperaton of
    '*' : Multiply;
    '/' : Divide;
    '+' : Add;
    '-' : Subtract
    end;[/code]
    As for error 26, [b]/[/b] is for [italic]real[/italic] number division and
    [b]div[/b] is for [italic]integer[/italic] division, which is what you've
    defined your numbers as.
    You also need an [italic]end;[/italic] for your Subtract
    procedure.
  • MiddleMiddle Posts: 6Member
    Excellent thanks a lot! I will try that in a minute and give you some more feedback in a bit!


    I should have known about the divide being a real number *derp*

    Thanks!
  • MiddleMiddle Posts: 6Member
    Do i make "case..." a new procedure?

    And then run it as

    Welcome;
    Obtain:
    case;
    Display;

    ?

    I am not too sure how to integrate this into what i have already, any further direction is greatly appreciated!

    thanks
  • MiddleMiddle Posts: 6Member
    Never mind i figured it out =]

    Thanks!
Sign In or Register to comment.