943,724 Members | Top Members by Rank

Ad:
Jul 1st, 2009
0

May I ask you a question on Delphi?

Expand Post »
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:

Pascal and Delphi Syntax (Toggle Plain Text)
  1. program sumof2numbers;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6. SysUtils;
  7.  
  8. Var
  9. number1, number2, total: integer;
  10.  
  11. begin
  12. writeln ('Please enter a number');
  13. readln (number1);
  14. writeln ('Please enter another number');
  15. readln (number2);
  16. total :=number1+number2;
  17. writeln ('The total of the two entered numbers is ',total,' ,');
  18. sleep (50000)

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

Cheers,
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
turbomen is offline Offline
113 posts
since Feb 2009
Jul 1st, 2009
0

Re: May I ask you a question on Delphi?

the answer is very simple...
delphi Syntax (Toggle Plain Text)
  1. Program sumof2numbers;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. Uses
  6. SysUtils;
  7.  
  8. Var
  9. number1, number2, total: integer;
  10. ch1,ch2:Char; {add 2 vars as chararacter type}
  11.  
  12. Begin
  13. ch1:='+';
  14. ch2:='=';
  15. writeln ('Please enter a number');
  16. readln (number1);
  17. writeln ('Please enter another number');
  18. readln (number2);
  19. total :=number1+number2;
  20. writeln ('The total of the two entered numbers is ');
  21. WriteLn(number1,ch1,number2,ch2,total);
  22. ReadLn;
  23. End.
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Jul 1st, 2009
0

Re: May I ask you a question on Delphi?

or more simple
delphi Syntax (Toggle Plain Text)
  1. Program sumof2numbers;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. Uses
  6. SysUtils;
  7.  
  8. Var
  9. number1, number2, total: integer;
  10.  
  11.  
  12. Begin
  13.  
  14. writeln ('Please enter a number');
  15. readln (number1);
  16. writeln ('Please enter another number');
  17. readln (number2);
  18. total :=number1+number2;
  19. writeln ('The total of the two entered numbers is ');
  20. WriteLn(number1,'+',number2,'=',total);{see this line}
  21. ReadLn;
  22. End.
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Jul 1st, 2009
0

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,
Reputation Points: 10
Solved Threads: 0
Junior Poster
turbomen is offline Offline
113 posts
since Feb 2009
Jul 1st, 2009
0

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);
Reputation Points: 10
Solved Threads: 0
Junior Poster
turbomen is offline Offline
113 posts
since Feb 2009
Jul 2nd, 2009
1

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
Reputation Points: 132
Solved Threads: 138
Posting Pro
FlamingClaw is offline Offline
559 posts
since Feb 2009
Jul 2nd, 2009
0

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

Dear Sir,

Thank you for your detailed expression.

Cheers,
Reputation Points: 10
Solved Threads: 0
Junior Poster
turbomen is offline Offline
113 posts
since Feb 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: using C# dlls in delphi
Next Thread in Pascal and Delphi Forum Timeline: Multithread+BDE+Oracle database Error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC