Could you tell me what is (are) wrong of my program?

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

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

Could you tell me what is (are) wrong of my program?

 
0
  #1
Jun 3rd, 2009
Dear Sir,

Could you tell me what is wrong of my program?

The question is: write a progrm that totals up a list of exactly 100 numbers and outputs that total to the screen, also show the average of the 100 numbers.

My program:
Pascal and Delphi Syntax (Toggle Plain Text)
  1. program Project2;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6. SysUtils;
  7.  
  8. var
  9. total, number, count: integer;
  10. average: real;
  11.  
  12. begin
  13. total:=0;
  14. for count:=1 to 100 do
  15. begin
  16. readln(number);
  17. total:=total+number;
  18. end;
  19. writeln(total);
  20. average:=total/100;
  21. writeln(average:6:2);
  22. end.
Last edited by Tekmaven; Jun 3rd, 2009 at 4:04 pm. Reason: Code Tags
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 4
Reputation: mark.b is an unknown quantity at this point 
Solved Threads: 1
mark.b mark.b is offline Offline
Newbie Poster

Re: Could you tell me what is (are) wrong of my program?

 
0
  #2
Jun 4th, 2009
Originally Posted by turbomen View Post
Dear Sir,

Could you tell me what is wrong of my program?

The question is: write a progrm that totals up a list of exactly 100 numbers and outputs that total to the screen, also show the average of the 100 numbers.

My program:
Pascal and Delphi Syntax (Toggle Plain Text)
  1. program Project2;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6. SysUtils;
  7.  
  8. var
  9. total, number, count: integer;
  10. average: real;
  11.  
  12. begin
  13. total:=0;
  14. for count:=1 to 100 do
  15. begin
  16. readln(number);
  17. total:=total+number;
  18. end;
  19. writeln(total);
  20. average:=total/100;
  21. writeln(average:6:2);
  22. end.

You may need to store average to a double (float), or maybe a variant.

Not sure which pascal you are using.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 450
Reputation: FlamingClaw will become famous soon enough FlamingClaw will become famous soon enough 
Solved Threads: 108
FlamingClaw's Avatar
FlamingClaw FlamingClaw is offline Offline
Posting Pro in Training

Re: Could you tell me what is (are) wrong of my program?

 
1
  #3
Jun 8th, 2009
Hi turbomen.
Your program is working well....where is the problem?
If you want to get the average result as decimals then
write here:
Write('The average is :',average:6:0);
got it?
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  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC