Quote:
> Ok, here's the output I want:
> This program is to do your calculating.
> Please enter A for Adding
> 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('Please enter A for Adding');
> 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}
> Procedure Adding;
> 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;
answer : double;
Begin
writeln('This program is to do your calculating');
writeln('Please enter A for Adding');
writeln('S for sub');
writeln('M for multipyling');
writeln
write('Enter your choice : ');
readln(c);
writeln('____________________________________________________');
write('Enter two number for ');
case c of
A : Begin
write('adding : ');
readln(num1,num2);
output := Adding(num1,num2);
end
S : Begin
write('subtracting (num1 - num2): ');
readln(num1,num2);
output := subtract(num1,num2);
end
M : Begin
write('Multipying : ');
readln(num1,num2);
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;
answer : double;
Begin
writeln('This program is to do your calculating');
writeln('Please enter A for Adding');
writeln('S for sub');
writeln('M for multipyling');
writeln
write('Enter your choice : ');
readln(c);
writeln('____________________________________________________');
write('Enter two number for ');
case c of
A : Begin
write('adding : ');
readln(num1,num2);
Adding(num1,num2,output);
end
S : Begin
write('subtracting (num1 - num2): ');
readln(num1,num2);
Subtract(num1,num2,output);
end
M : Begin
write('Multipying : ');
readln(num1,num2);
Multiply(num1,num2,output);
end
End;
writeln;
writeln;
writeln('The output is ',output:2:2);
End.