Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
cube Math Posted by sweeney on 15 Jul 2003 at 3:19 PM
I am writeing a program for my uncle how is a builder! the first thing iam doing is a room with 4 sides like a cube or rectangle, finding the area of each side then asking if there are any windows. this is were my problem comes in,

for loop := 1 to NumWin do
begin
write(' enter the length of window ', loop,': ');
readln(lengthW1);
write(' enter the breadth of window ', loop,': ');
readln(breadthW1);

totalAreaW := lengthW1 * breadthW1;
write(totalAreaW);

end;

my problem is that when I call the totalAreaW1 for each window I dont know how to add them all together. I can do the calculation but it will only add one of the turns! how can I do this?
Report
Re: cube Math Posted by Phat Nat on 15 Jul 2003 at 10:50 PM
: I am writeing a program for my uncle how is a builder! the first thing iam doing is a room with 4 sides like a cube or rectangle, finding the area of each side then asking if there are any windows. this is were my problem comes in,
:
: for loop := 1 to NumWin do
: begin
: write(' enter the length of window ', loop,': ');
: readln(lengthW1);
: write(' enter the breadth of window ', loop,': ');
: readln(breadthW1);
:
: totalAreaW := lengthW1 * breadthW1;
: write(totalAreaW);
:
: end;
:
: my problem is that when I call the totalAreaW1 for each window I dont know how to add them all together. I can do the calculation but it will only add one of the turns! how can I do this?

totalAreaW := 0;
for loop := 1 to NumWin do
  begin
   write(' enter the length of window ', loop,': ');
    readln(lengthW1);
   write(' enter the breadth of window ', loop,': ');
    readln(breadthW1);

   totalAreaW := totalAreaW + (lengthW1 * breadthW1);
  end;
write(totalAreaW);

Report
Re: cube Math Posted by sweeney on 17 Jul 2003 at 2:08 PM
: : I am writeing a program for my uncle how is a builder! the first thing iam doing is a room with 4 sides like a cube or rectangle, finding the area of each side then asking if there are any windows. this is were my problem comes in,
: :
: : for loop := 1 to NumWin do
: : begin
: : write(' enter the length of window ', loop,': ');
: : readln(lengthW1);
: : write(' enter the breadth of window ', loop,': ');
: : readln(breadthW1);
: :
: : totalAreaW := lengthW1 * breadthW1;
: : write(totalAreaW);
: :
: : end;
: :
: : my problem is that when I call the totalAreaW1 for each window I dont know how to add them all together. I can do the calculation but it will only add one of the turns! how can I do this?
:
:
: totalAreaW := 0;
: for loop := 1 to NumWin do
:   begin
:    write(' enter the length of window ', loop,': ');
:     readln(lengthW1);
:    write(' enter the breadth of window ', loop,': ');
:     readln(breadthW1);
: 
:    totalAreaW := totalAreaW + (lengthW1 * breadthW1);
:   end;
: write(totalAreaW);
: 

:

but if the user types in 2 windows, it calculates area of window1 and window2, but when It comes to add these together it just calculets window2.

thanks

Sweeney

Report
Re: cube Math Posted by Phat Nat on 20 Jul 2003 at 1:38 AM
: : : I am writeing a program for my uncle how is a builder! the first thing iam doing is a room with 4 sides like a cube or rectangle, finding the area of each side then asking if there are any windows. this is were my problem comes in,
: : :
: : : for loop := 1 to NumWin do
: : : begin
: : : write(' enter the length of window ', loop,': ');
: : : readln(lengthW1);
: : : write(' enter the breadth of window ', loop,': ');
: : : readln(breadthW1);
: : :
: : : totalAreaW := lengthW1 * breadthW1;
: : : write(totalAreaW);
: : :
: : : end;
: : :
: : : my problem is that when I call the totalAreaW1 for each window I dont know how to add them all together. I can do the calculation but it will only add one of the turns! how can I do this?
: :
: :
: : totalAreaW := 0;
: : for loop := 1 to NumWin do
: :   begin
: :    write(' enter the length of window ', loop,': ');
: :     readln(lengthW1);
: :    write(' enter the breadth of window ', loop,': ');
: :     readln(breadthW1);
: : 
: :    totalAreaW := totalAreaW + (lengthW1 * breadthW1);
: :   end;
: : write(totalAreaW);
: : 

: :
:
: but if the user types in 2 windows, it calculates area of window1 and window2, but when It comes to add these together it just calculets window2.
:
: thanks
:
: Sweeney

Notice the changes I made (In Bold). These will calculate them into one variable that contains the total area of the windows. It doesn't overwrite the first value, just adds it on to the first one.

Phat Nat

PS- Try it. Two windows, each 4'x4' should have an area of 2*4'*4' = 2*64 sqft = 128 sqft. (64 each, 128 together)



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.