Help with iteration in 'while' loop

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2004
Posts: 3
Reputation: Jo_1660 is an unknown quantity at this point 
Solved Threads: 0
Jo_1660 Jo_1660 is offline Offline
Newbie Poster

Help with iteration in 'while' loop

 
1
  #1
Jun 5th, 2004
Hi,

I am trying to write an engine simulation program in C++ - please not that I have never done any programming.

I have attached what I have done so far which is a program that calculates the cylinder volume from a crank angle (theta). What I need now to do is use those iterations to find the pressure at each crank angle - the function is in the form of:
P(theta + dtheta) = P(theta) * (V(theta)/V(theta + dtheta))
ie the current pressure is found using the pressure from the previous iteration, the current volume and the previous volume.

How do I write program to use both the current and previous values for volume? Im sure it can be done, I just can't figure out how to do it.

Any help would be appreciated!
Attached Files
File Type: cpp vol loop4.cpp (1.3 KB, 9 views)
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,056
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 129
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Help with iteration in 'while' loop

 
0
  #2
Jun 5th, 2004
It's 3 am here so I can't offer much assistance for the simple fact that I am having a hard time keeping my eyes open. But here is some food for thought until you get better replies: http://www.daniweb.com/forums/thread1734.html
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 217
Reputation: marceta is an unknown quantity at this point 
Solved Threads: 0
marceta marceta is offline Offline
Posting Whiz in Training

Re: Help with iteration in 'while' loop

 
0
  #3
Jun 5th, 2004
@cscgal
go to bed earlier!


You say you have never done any programming. This is not really that easy of a thing to do. Start out simple!
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 3
Reputation: Jo_1660 is an unknown quantity at this point 
Solved Threads: 0
Jo_1660 Jo_1660 is offline Offline
Newbie Poster

Re: Help with iteration in 'while' loop

 
0
  #4
Jun 5th, 2004
Yeah tell me about it!

Unfortunately I don't have any choice. I'm doing my final year project on engine simulations and I was under the naive impression that I would have a program to use! So now I have to write my own. :lol:
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: Help with iteration in 'while' loop

 
0
  #5
Jun 7th, 2004
Originally Posted by marceta
@cscgal
go to bed earlier!
Yea you should.Leave lights on at night if you are using the comp
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 95
Reputation: gusano79 is on a distinguished road 
Solved Threads: 10
gusano79 gusano79 is offline Offline
Junior Poster in Training

Re: Help with iteration in 'while' loop

 
0
  #6
Jun 7th, 2004
Originally Posted by Jo_1660
...
How do I write program to use both the current and previous values for volume? Im sure it can be done, I just can't figure out how to do it.
...
If you only need one previous value, there is a simple answer to your question: Use two volume variables.

It looks like you already have two, i.e. V and V2, but you're only using one of them. I'd rename V2 something more descriptive, like OldV or something, and make it so V has a value before you start the loop. The only addition to the loop would be to add a line at the start that says 'OldV = V;'--then you can do whatever you want with V in the loop body, since you've already stored the previous value. Once you've calculated a new value for V, you can use both the current and previous values as much as you want. OldV will only ever hold the most recent value of V.

Hope that helps.
--sg
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 3
Reputation: Jo_1660 is an unknown quantity at this point 
Solved Threads: 0
Jo_1660 Jo_1660 is offline Offline
Newbie Poster

Re: Help with iteration in 'while' loop

 
0
  #7
Jun 8th, 2004
Thank You!!!!

That worked very easily.

:lol: :!:
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC