I am trying to make a simple calculator, unfortunately, it isn't going so well.
Any ideas on how to make it simple?

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

  if symbol='+' then       {addition}
 begin
  clrscr;
  title;
  writeln ('Addition Problem (One time use only)');
  writeln;
  writeln ('Enter two numbers(with spaces) to solve out.(No decimal numbers)');
  readln (add1,add2);
  addresult:=add1+add2;
  writeln;
  writeln ('The result is ',addresult);
  readln;
  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)');
  readln (sub1,sub2);
  subresult:=sub1-sub2;
  writeln;
  writeln ('The result is ',subresult);
  readln;
  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)');
  readln (mult1,mult2);
  multresult:=mult1*mult2;
  writeln;
  writeln ('The result is ',multresult);
  readln;
  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)');
  readln (div1,div2);
  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);
  readln;
  clrscr;
  title;
  quit;
  end;
end

Recommended Answers

All 2 Replies

'Enter two numbers(with spaces) to solve out.(No decimal numbers)'

Extend this instruction to include an operator between two spaces.
Now after the user enters a number, a space, an operator, a space and a number, you have your operation and rework the whole thing in one case statement.

Much easier. Thank you so much.

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.