May I ask you a question on Delphi?

Thread Solved
Reply

Join Date: Feb 2009
Posts: 93
Reputation: turbomen is an unknown quantity at this point 
Solved Threads: 0
turbomen turbomen is offline Offline
Junior Poster in Training

May I ask you a question on Delphi?

 
0
  #1
Jul 1st, 2009
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,
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 443
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 106
FlamingClaw's Avatar
FlamingClaw FlamingClaw is offline Offline
Posting Pro in Training

Re: May I ask you a question on Delphi?

 
0
  #2
Jul 1st, 2009
the answer is very simple...
  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.
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 443
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 106
FlamingClaw's Avatar
FlamingClaw FlamingClaw is offline Offline
Posting Pro in Training

Re: May I ask you a question on Delphi?

 
0
  #3
Jul 1st, 2009
or more simple
  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.
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 93
Reputation: turbomen is an unknown quantity at this point 
Solved Threads: 0
turbomen turbomen is offline Offline
Junior Poster in Training

Re: May I ask you a question on Delphi?

 
0
  #4
Jul 1st, 2009
Dear Sir,

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

Cheers,
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 93
Reputation: turbomen is an unknown quantity at this point 
Solved Threads: 0
turbomen turbomen is offline Offline
Junior Poster in Training

Re: May I ask you a question on Delphi?

 
0
  #5
Jul 1st, 2009
Would you tell me something about the use of 'delimiter' and 'comma' and 'semi-colon'?

Just like the following line:

WriteLn(number1,'+',number2,'=',total);
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 443
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 106
FlamingClaw's Avatar
FlamingClaw FlamingClaw is offline Offline
Posting Pro in Training

Re: May I ask you a question on Delphi?

 
1
  #6
Jul 2nd, 2009
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
Be a good part of the community.Don't be ungrateful.
If you ask something on the forum and you got the right answer then mark as solved!
If my opinion helped to you a lot then sometimes give reputation point to me.
I'm just a pascal programmer from Hungary.
Farewell...
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 93
Reputation: turbomen is an unknown quantity at this point 
Solved Threads: 0
turbomen turbomen is offline Offline
Junior Poster in Training

Re: May I ask you a question on Delphi?

 
0
  #7
Jul 2nd, 2009
Originally Posted by FlamingClaw View Post
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,
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC