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

Program calculation;
uses wincrt;

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

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

Procedure Add;
          var
             add:integer;
          Begin
               clrscr;
               add:=GetUserInput('Enter another number:')+GetUserInput('Enter a number:');
               writeln('Result=',add);
          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:');
               Readln(option);
               If ((option<1) or (option>5)) then
                  writeln('Error wrong input')
               Else
                   If (option=1) Then
                      Add;
                   If (option=2) Then
                      Subtract;
          end;


Begin {main}
     menu;
     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

Member Avatar for Micheus

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??
reply plz

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.