DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Pascal and Delphi (http://www.daniweb.com/forums/forum124.html)
-   -   May I ask you a question on Delphi? (http://www.daniweb.com/forums/thread200899.html)

turbomen Jul 1st, 2009 7:10 am
May I ask you a question on Delphi?
 
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,

FlamingClaw Jul 1st, 2009 10:47 am
Re: May I ask you a question on Delphi?
 
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.

FlamingClaw Jul 1st, 2009 10:49 am
Re: May I ask you a question on Delphi?
 
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.

turbomen Jul 1st, 2009 10:14 pm
Re: May I ask you a question on Delphi?
 
Dear Sir,

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

Cheers,

turbomen Jul 1st, 2009 11:02 pm
Re: May I ask you a question on Delphi?
 
Would you tell me something about the use of 'delimiter' and 'comma' and 'semi-colon'?

Just like the following line:

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

FlamingClaw Jul 2nd, 2009 1:50 pm
Re: May I ask you a question on Delphi?
 
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

turbomen Jul 2nd, 2009 6:56 pm
Re: May I ask you a question on Delphi?
 
Quote:

Originally Posted by FlamingClaw (Post 906674)
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,


All times are GMT -4. The time now is 6:55 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC