Author Message

Ok, here's the output I want:

This program is to do your calculating.
S for subtracting
M for multiply

{User enters A}

Enter a number:
{User enters x}
Enter another number
{User enters x}
The answer is n.

And so forth.

This how i did mine and it was kinda unsuccessful.

Program Calculating;
var c:char;
Begin
writeln('This program is to do your calculating');
writeln('S for sub')
writeln('M for multipyling')
{ now here's where things get messed up}
IF c:=A then goto Adding;
IF c:=S then goto Subtracting;
{and so on}

var bla bla bla
{ I know how to do this part}
It's calling up the procedure that is hard for me

i wonder if anybody can correct me or better still give me a sample :)

THANKS!!!!

Wed, 18 Jun 1902 08:00:00 GMT

Quote:
> Ok, here's the output I want:

> This program is to do your calculating.
> S for subtracting
> M for multiply

> {User enters A}

> Enter a number:
> {User enters x}
> Enter another number
> {User enters x}
> The answer is n.

> And so forth.

> This how i did mine and it was kinda unsuccessful.

> Program Calculating;
> var c:char;
> Begin
>   writeln('This program is to do your calculating');
>   writeln('S for sub')
>   writeln('M for multipyling')
> { now here's where things get messed up}
> IF c:=A then goto Adding;
> IF c:=S then goto Subtracting;
> {and so on}

>  var bla bla bla
> { I know how to do this part}
> It's calling up the procedure that is hard for me

> i wonder if anybody can correct me or better still give me a sample :)

> THANKS!!!!

I will give you 2 version, but I personally thought that if there is only
one answer use a function will look cleaner(well I could be wrong, you
know). I am not against the statement 'goto' but try not to use it unless
absoutely (which is very seldom) necessary. Any more question feel free

as I can (but don't abuse it).

Program Calculating;
{Function Edition}

Function Adding(Input1 , Input2 : double) : double;

Begin

Adding := Input1 + Input2;
End;

Function Subtract(Input1, Input2 : double) : double;

Begin

Subtract := Input1 - Input2;
End;

Function Multiply(Input1, Input2 : double) : double;

Begin
Multiply := Input1 * Input2 : double) : double;

End;

var c            :    char;
num1, num2   :    double;

Begin
writeln('This program is to do your calculating');
writeln('S for sub');
writeln('M for multipyling');
writeln
write('Enter your choice : ');
writeln('____________________________________________________');

write('Enter two number for ');
case  c of
A             :       Begin
end

S             :       Begin
write('subtracting (num1 - num2): ');
output := subtract(num1,num2);
end

M             :       Begin
write('Multipying : ');
output := Multiply(num1,num2);
end

End;

writeln;
writeln;
writeln('The output is ',output:2:2);

End.

___________________________________________________________

Program Calculating;
{Procedure Edition}

Procedure Adding(Input1 , Input2 : double; VAR Output : double);

Begin

Adding := Input1 + Input2;
End;

Function Subtract(Input1, Input2 : double; VAR Output : double);

Begin

Subtract := Input1 - Input2;
End;

Function Multiply(Input1, Input2 : double; VAR Output : Double);

Begin
Multiply := Input1 * Input2 : double) : double;

End;

var c            :    char;
num1, num2   :    double;

Begin
writeln('This program is to do your calculating');
writeln('S for sub');
writeln('M for multipyling');
writeln
write('Enter your choice : ');
writeln('____________________________________________________');

write('Enter two number for ');
case  c of
A             :       Begin
end

S             :       Begin
write('subtracting (num1 - num2): ');
Subtract(num1,num2,output);
end

M             :       Begin
write('Multipying : ');
Multiply(num1,num2,output);
end

End;

writeln;
writeln;
writeln('The output is ',output:2:2);

End.

Wed, 18 Jun 1902 08:00:00 GMT

Quote:

>Ok, here's the output I want:

>This program is to do your calculating.
>S for subtracting
>M for multiply

>{User enters A}

>Enter a number:
>{User enters x}
>Enter another number
>{User enters x}
>The answer is n.

69696969696969696969696969696969696969696969696969
Well, hope this will work for you....

Program Calculate;

var
choose:char;
num1,num2: integer;

begin
WriteLn(num1, ' + ', num2,' = ',num1+num2);
end;

Procedure Subtracting(num1,num2:integer);
begin
WriteLn(num1, ' - ', num2,' = ',num1-num2);
end;

Procedure Multiplying(num1,num2:integer);
begin
WriteLn(num1, ' * ', num2,' = ',num1*num2);
end;

Begin
WriteLn('S = Subtracting');
WriteLn('M = Multiplying');
Write('Please enter the letter of your choice: ');
Write('Enter first number: ');
Write('Enter second number: ');
If choose = 'A' then Adding(num1,num2)
Else If choose = 'S' then Subtracting(num1,num2)
Else If choose = 'M' then Multiplying(num1,num2)
Else WriteLn('Error - Invalid choice!');
End.

The above code is just a sample.  The code below is how I'd do it.

Program Calculate;

var
choice: char;
num1,num2:integer;

Begin
WriteLn('[A]dding / [S]ubtracting / [M]ultiplying');
WriteLn('What would you like to do? [A/S/M]:');
Write('Enter first number: ');
Write('Enter second number: ');
Case Upcase(choice) of
'A': WriteLn(num1, ' + ', num2,' = ',num1+num2);
'S': WriteLn(num1, ' - ', num2,' = ',num1-num2);
'M': WriteLn(num1, ' * ', num2,' = ',num1*num2);
else
WriteLn('Error - Invalid choice!);
end;
End.
696969696969696969696969696969696969696969696969

Wed, 18 Jun 1902 08:00:00 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages