Does anyone have an idea of how I should make a simple calculator without the case function?

That is one way. (There are of course other ways.)

Why do you say this is too big coding? Too much typing? Too much to understand? Requires too much memory? In reality it is a tiny program.

If you just think it is too much code to type or read, …

## All 4 Replies

The CASE statement can be replaced by a series of IF statements.

If your talking something like this, it is too big of a coding.

``````if gamemode=1 then                                                                   {If gamemode 1 has been chosen}
begin
clrscr;
title;
writeln ('Welcome to Calculator');
writeln;
writeln ('To begin, press <Enter>');
clrscr;
title;
writeln ('Choose which symbol is needed');
writeln ('"+" "-" "*" "/"');

begin
clrscr;
title;
writeln ('Addition Problem (One time use only)');
writeln;
writeln ('Enter two numbers(with spaces) to solve out.(No decimal numbers)');
writeln;
clrscr;
title;
quit;
end;

if symbol='-' then      {subtraction}
begin
clrscr;
title;
writeln ('Subtraction Problem (One time use only)');
writeln;
writeln ('Enter two numbers(with spaces) to solve out.(No decimal numbers)');
subresult:=sub1-sub2;
writeln;
writeln ('The result is ',subresult);
clrscr;
title;
quit;
end;

if symbol='*' then      {multiplication}
begin
clrscr;
title;
writeln ('Multiplication Problem (One time use only)');
writeln;
writeln ('Enter two numbers(space after one number) to solve out.(No decimal numbers or symbols)');
multresult:=mult1*mult2;
writeln;
writeln ('The result is ',multresult);
clrscr;
title;
quit;
end;

if symbol='/' then     {division}
begin
clrscr;
title;
writeln ('Division Problem (One time use only)');
writeln;
writeln ('Enter two numbers(with spaces) to solve out.(No decimal numbers)');
if div2<=0 then
begin
clrscr;
title;
writeln ('Syntax Error, Denominator can not be less than 0');
quit;
end;
divresult:=div1 div div2;
writeln;
writeln ('The result is ',divresult:1:5);
clrscr;
title;
quit;
end;
end
``````

That is one way. (There are of course other ways.)

Why do you say this is too big coding? Too much typing? Too much to understand? Requires too much memory? In reality it is a tiny program.

If you just think it is too much code to type or read, you could trim it down quite easily. For example:

``````if gamemode=1 then                                                                   {If gamemode 1 has been chosen}
begin
clrscr;
title;
writeln ('Welcome to Calculator');
writeln;
writeln ('To begin, press <Enter>');
clrscr;
title;
writeln ('Choose which symbol is needed');
writeln ('"+" "-" "*" "/"');
clrscr;
title;
writeln ('Addition Problem (One time use only)')
else if symbol='-' then      {subtraction}
writeln ('Subtraction Problem (One time use only)');
else if symbol='*' then      {multiplication}
writeln ('Multiplication Problem (One time use only)');
else if symbol='/' then     {division}
writeln ('Division Problem (One time use only)');
writeln;
writeln ('Enter two numbers(with spaces) to solve out.(No decimal numbers)');
CalcResult := Val1 + Val2
else if symbol='-' then      {subtraction}
CalcResult := Val1 - Val2
else if symbol='*' then      {multiplication}
CalcResult := Val1 * Val2
else if symbol='/' then     {division}
CalcResult := Val1 / Val2;
writeln;
writeln ('The result is ',CalcResult);
clrscr;
title;
quit;
end.
``````

Well, from what I meant that it was big is that the the whole program which I am writing is alot of coding and this takes up the majority of it.

Because of the fact that I am on Windows XP, it is harder for me to scroll down trying to find my program.

Thanks for that coding, it will help me out.

Be a part of the DaniWeb community

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