all work perfectly just the substraction here's the code:

``````Program calculation;
uses wincrt;

Begin
Writeln('Options:');
Writeln('2. Subtraction');
Writeln('3. Mutiplication');
Writeln('4. Division');
Writeln('5. Exit');
End;

Function GetUserInput(msg:string):integer;
Var
UserInput:integer;
Begin
Write(msg);
GetUserInput:=Userinput;
End;

var
Begin
clrscr;
End;

Procedure subtract;
var
subtract:integer;
Begin
clrscr;
subtract:=GetUserInput('Enter another number:')-GetUserInput('Enter a number:');
writeln('Result=',subtract);
End;

Procedure SelectOption;
var
option:integer;
Begin
write('Select an option:');
If ((option<1) or (option>5)) then
writeln('Error wrong input')
Else
If (option=1) Then
If (option=2) Then
Subtract;
end;

Begin {main}
SelectOption;

end.``````

my prob is here:

``subtract:=GetUserInput('Enter another number:')-GetUserInput('Enter a number:');``

pascal read Enter a number first and then read enter another number, so this id because i put enter another number first and then enter a number.

example
Enter a number: 23
Enter another number:1 (remember this is substraction)
Result = -22 (wrong result, good result is 22)

how to solve it

its very long but i explain my prob so any help plz

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by manutd4life

manutd4life230, just try this:

``subtract:= -GetUserInput('Enter another number:') +GetUserInput('Enter a number:');``

just because:
Enter a number = 1stValue
Enter another number = 2ndValue

then:
subtract := -2ndValue +1stValue

is equivalent to:
subtract := +1stValue -2ndValue

Bye

Thanks man all work perfectly

Any 1 no wat the code for exit??