May I ask you a question on Delphi? The following is my question:

Write a program that asks for two numbers from the user. Add these numbers together and store them. Then output to the screen the equation with the correct answer. Eg

please enter a number
28
please enter another number
3
thank you
28 + 3 = 31

But I do in this way:

program sumof2numbers;

{$APPTYPE CONSOLE}

uses
  SysUtils;

Var
  number1, number2, total: integer;

begin
  writeln ('Please enter a number');
  readln (number1);
  writeln ('Please enter another number');
  readln (number2);
  total :=number1+number2;
  writeln ('The total of the two entered numbers is ',total,' ,');
  sleep (50000)

Could you tell me how can I show: 28 + 3 = 31 ??

Cheers,

the answer is very simple...

Program sumof2numbers;

{$APPTYPE CONSOLE}

Uses
  SysUtils;

Var
  number1, number2, total: integer;
  ch1,ch2:Char;  {add 2 vars as chararacter type}

Begin
  ch1:='+';
  ch2:='=';
  writeln ('Please enter a number');
  readln (number1);
  writeln ('Please enter another number');
  readln (number2);
  total :=number1+number2;
  writeln ('The total of the two entered numbers is ');
  WriteLn(number1,ch1,number2,ch2,total);
  ReadLn;
End.

or more simple

Program sumof2numbers;

{$APPTYPE CONSOLE}

Uses
  SysUtils;

Var
  number1, number2, total: integer;


Begin

  writeln ('Please enter a number');
  readln (number1);
  writeln ('Please enter another number');
  readln (number2);
  total :=number1+number2;
  writeln ('The total of the two entered numbers is ');
  WriteLn(number1,'+',number2,'=',total);{see this line}
  ReadLn;
End.

Dear Sir,

Thank you for your help. I have got a serious problem on some of the basic skill on programming.

Cheers,

Would you tell me something about the use of 'delimiter' and 'comma' and 'semi-colon'?

Just like the following line:

WriteLn(number1,'+',number2,'=',total);

In the pascal lang almost every commands ended with semicolon ;
except Begin or the end of the main program End.,it is ended with dot.
if you want to know a contetnt of a variable then you have to reference it by its name without apostrophe.
Look at this example:

Program commas_and_delimiters;

Var digit:Char;

Begin

digit:='#';

WriteLn(digit); {this line writes digit's contents,like #}

{if you want to write to the screen then do it by apostrophe}
WriteLn('Press enter to quit...');


{if you want to write to the screen and write the contents
of digit
, detach them with comma}
WriteLn('The first character is ',digit);


{if you have another thought too,then detach with comma and
put the thoughts after that,of course between apostrophe
}
WriteLn('The first character is ',digit,'.Guess it please');


{if you want to write to the screen four times
the contents of the reserved area
by the compiler,called digit
,call its name detach them with comma}
WriteLn(digit,digit,digit,digit);


End.{end of main program}

I hope that you understood now :D

commented: He expresses very well to me. +1

In the pascal lang almost every commands ended with semicolon ;
except Begin or the end of the main program End.,it is ended with dot.
if you want to know a contetnt of a variable then you have to reference it by its name without apostrophe.
Look at this example:

Program commas_and_delimiters;

Var digit:Char;

Begin

digit:='#';

WriteLn(digit); {this line writes digit's contents,like #}

{if you want to write to the screen then do it by apostrophe}
WriteLn('Press enter to quit...');


{if you want to write to the screen and write the contents
of digit
, detach them with comma}
WriteLn('The first character is ',digit);


{if you have another thought too,then detach with comma and
put the thoughts after that,of course between apostrophe
}
WriteLn('The first character is ',digit,'.Guess it please');


{if you want to write to the screen four times
the contents of the reserved area
by the compiler,called digit
,call its name detach them with comma}
WriteLn(digit,digit,digit,digit);


End.{end of main program}

I hope that you understood now :D

Dear Sir,

Thank you for your detailed expression.

Cheers,

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.