943,806 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4689
  • C++ RSS
Jun 5th, 2004
1

Help with iteration in 'while' loop

Expand Post »
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, 31 views)
Similar Threads
Reputation Points: 11
Solved Threads: 0
Newbie Poster
Jo_1660 is offline Offline
3 posts
since Jun 2004
Jun 5th, 2004
0

Re: Help with iteration in 'while' loop

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/showthread.php?t=1734
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Jun 5th, 2004
0

Re: Help with iteration in 'while' loop

@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!
Reputation Points: 13
Solved Threads: 0
Posting Whiz in Training
marceta is offline Offline
217 posts
since May 2004
Jun 5th, 2004
0

Re: Help with iteration in 'while' loop

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:
Reputation Points: 11
Solved Threads: 0
Newbie Poster
Jo_1660 is offline Offline
3 posts
since Jun 2004
Jun 7th, 2004
0

Re: Help with iteration in 'while' loop

Quote originally posted by marceta ...
@cscgal
go to bed earlier!
Yea you should.Leave lights on at night if you are using the comp
Reputation Points: 108
Solved Threads: 7
Posting Whiz in Training
FireNet is offline Offline
256 posts
since May 2004
Jun 7th, 2004
0

Re: Help with iteration in 'while' loop

Quote 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
Reputation Points: 182
Solved Threads: 71
Posting Pro in Training
gusano79 is offline Offline
475 posts
since May 2004
Jun 8th, 2004
0

Re: Help with iteration in 'while' loop

Thank You!!!!

That worked very easily.

:lol: :!:
Reputation Points: 11
Solved Threads: 0
Newbie Poster
Jo_1660 is offline Offline
3 posts
since Jun 2004

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 C++ Forum Timeline: i want the user to enter an input without obligating him to press enter
Next Thread in C++ Forum Timeline: basic fstream stuff





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


Follow us on Twitter


© 2011 DaniWeb® LLC