| | |
Help with iteration in 'while' loop
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2004
Posts: 3
Reputation:
Solved Threads: 0
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!
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!
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

Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
•
•
•
•
Originally Posted by marceta
@cscgal
go to bed earlier!
•
•
Join Date: May 2004
Posts: 95
Reputation:
Solved Threads: 10
•
•
•
•
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.
...
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
![]() |
Similar Threads
- Print Prime Numbers(using for loop) (C)
- how to create each file for each iteration using loop (Java)
- test condition in a for loop (Java)
- Alright this loop problem is bugging me (Java)
- For loop (C++)
- while loop (C)
Other Threads in the C++ Forum
- Previous Thread: i want the user to enter an input without obligating him to press enter
- Next Thread: basic fstream stuff
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






