473,788 Members | 2,905 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Having problems with a loop

void generation_loop ()
{
int generation = 1;
double x = 0.25;
double y = 0.50;
double z = 0.25;
double AA, AB, BB;
double p = (y/(y+z))/2;
AA = pow(p,2);
AB = 2*p*(1-p);
BB = pow(1-p,2);
double p2 = (AB /(AB+BB))/2;
for (generation = 1; generation <= 30; generation++)
{
cout << "Generation " << generation << " ";
cout << x << " "<< y << z << endl;
}
}
I've been pulling my hair out on this. For each time a generation has
passed I want a new value computed. The prevous value should be saved
in x,y,z and then recomputed with the new values.

Feb 25 '06 #1
5 1359
cout << x << " "<< y << z << endl;

that line is supposed to be
cout << AA << AB << BB;

Feb 25 '06 #2
void generation_loop ()
{
int generation = 1;
double x = 0.25;
double y = 0.50;
double z = 0.25;
double AA, AB, BB;
double p = (y/(y+z))/2;
AA = pow(p,2);
AB = 2*p*(1-p);
BB = pow(1-p,2);
double p2 = (AB /(AB+BB))/2;
for (generation = 1; generation <= 30; generation++)
{
cout << "Generation " << generation << " ";
cout << AA << " "<< AB << BB << endl;
x = AA;
y = AB;
z = BB;
}
}

The updated problem. maybe a little more clear.

Feb 25 '06 #3
void generation_loop ()
{
int generation = 1;
double x = 0.25;
double y = 0.50;
double z = 0.25;
double AA, AB, BB;
double p = (y/(y+z))/2;
AA = pow(p,2);
AB = 2*p*(1-p);
BB = pow(1-p,2);
double p2 = (AB /(AB+BB))/2;
for (generation = 1; generation <= 30; generation++)
{
cout << "Generation " << generation << " ";
cout << AA << " "<< AB << BB << endl;
x = AA;
y = AB;
z = BB;
}
}

The updated problem. maybe a little more clear.

Feb 25 '06 #4
Brian wrote:
void generation_loop ()
{
int generation = 1;
double x = 0.25;
double y = 0.50;
double z = 0.25;
double AA, AB, BB;
double p = (y/(y+z))/2;
AA = pow(p,2);
AB = 2*p*(1-p);
BB = pow(1-p,2);
double p2 = (AB /(AB+BB))/2;
for (generation = 1; generation <= 30; generation++)
{
cout << "Generation " << generation << " ";
cout << AA << " "<< AB << BB << endl;
x = AA;
y = AB;
z = BB;
}
}

The updated problem. maybe a little more clear.


If you are expecting AA, AB, and BB to change each time around the loop
then the computation of them has to be inside the loop.

--
Scott McPhillips [VC++ MVP]

Feb 25 '06 #5
"Brian" <br************ @gmail.com> writes:
void generation_loop ()
{
int generation = 1;
double x = 0.25;
double y = 0.50;
double z = 0.25;
double AA, AB, BB;
double p = (y/(y+z))/2;
AA = pow(p,2);
AB = 2*p*(1-p);
BB = pow(1-p,2);
double p2 = (AB /(AB+BB))/2;
for (generation = 1; generation <= 30; generation++)
{
cout << "Generation " << generation << " ";
cout << x << " "<< y << z << endl;
}
}
I've been pulling my hair out on this. For each time a generation has
passed I want a new value computed. The prevous value should be saved
in x,y,z and then recomputed with the new values.


Do you want to do something like the following?

[[[
#include <iostream>
using namespace std;

double calculateNextGe neration(double recent)
{
return 0.5 * recent; // Arbitrary rule to get some new value.
}

int main()
{
int generation = 1;
double someParameter = 0.42;
double AA = 42.0;
double lastAA = AA;
for (generation = 1; generation <= 30; generation++)
{
cout << "Generation " << generation << " ";
cout << AA << endl;
if(generation > 1)
cout << "BTW: The last generation was: " << lastAA << "." << endl;
lastAA = AA;
AA = calculateNextGe neration(AA);
}
return 0;
}
]]]

Feb 25 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
3314
by: Markku Uttula | last post by:
I think I'm doing something wrong. I'm able to connect to Oracle just fine, execute queries and all, but I'm having serious problems with the speed :( For example, the following PHP-script on my machine executes about 6 seconds: <? $db_conn = ocilogon("my_username", "my_password", "my_database"); $loop_count = 1000;
1
354
by: malcolm | last post by:
Hello, We have a small team building a project that involves some 30 or so c# assembly dlls. It is a client server application with 1 exe as the starting point. The dlls and exe are sharing an assemblyinfo file that has a strong name and version assiciated with it. We are having problems in the way we have been developing. We have made two attempts at this. Attempt 1) In our first attempt, we basically had 1 folder that
6
2316
by: damian birchler | last post by:
If I run the following I get a segmentation fault: #define NAMELEN 15 #define NPERS 10 typedef struct pers { char name; int money; } pers_t;
0
2991
by: Sherif ElMetainy | last post by:
Hello I am making an application that generates source code. I am facing some problems. 1- How can I generate code that uses the c# 'params' keyword to specify multiple arguments? I tried 2 ways method.Parameters.Add(new CodeParameterDeclarationExpression("params object", name));
4
1618
by: Charles | last post by:
I am still having problems with sessions crossing over from other sessions. What I mean by this is that Mary may get just some or all of Renae’s information. I think that what is going on with this problem is the way that I have the solution setup I have this .NET CEmployees class that I am storing into a session object. The sessions are stored using SQL Server. I also have this ActiveX DLL file created in VB6. The ActiveX DLL file has...
2
1841
by: shblack | last post by:
I need help with a program I am writing for school. The program has to do the following: /* 1. Character string must be a minimium of 15 charactors. 2. If not 15 characters long it must give error and send you back to orginal question. 3. After entering 15 characters it must count the CAPTIAL letters and tell you how many there are. 4. Need a loop to count and produce error and take you back to first screen. */
0
1720
grassh0pp3r
by: grassh0pp3r | last post by:
Hello, I'm trying to make a very simple comments page on my site using PHP and am having problems somewhere. I am very new to PHP. I was able to create one that works with comments appended, but I want the latest comment to be on top, and that's where I'm running into trouble. Since I know very little about PHP, I thought I was clever in what I came up with. I think it can work if I get the coding right. Let me know if my logic is wrong. I'm...
6
1892
by: JNeko | last post by:
Hello all, awesome site! I guess I am technically not a beginner in JAVA, but from my code you would not realize it! I don’t expect anyone to help me with this, but I figure I might as well as try and ask. Any help is really appreciated; this should be a piece of cake…driving me crazy. I am writing a simple program (from a book for fun) that creates a deck of cards, shuffles them, gives the user a card, and asks if the next card will be...
4
2192
by: mayen001 | last post by:
Hi First time i am posting a question so here goes... I have created a bit of VBA for pupils where the aim is: input line of text from file;parse the input line and extract values; using the AddNew, populate the respetive fields in the table. General outline is: Set cncurrent = CurrentProject.Connection Set rsDiag = New ADODB.Recordset 'Open the database table strsql = "Select * from tblEquipment" rsDiag.Open strsql, cncurrent,...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.