473,396 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to use input from first operation as variable in second operation

How do I get the program to take the "Population" calculated from the first time and use it as the "initial" variable for the next calculation. And for it to continue to do this for generations 2 on each time taking the previously calculated Population and using it as the variable "initial" for the next calculation. With what I have right now when I run the program it just kind of... pauses after I give all the inputs.

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<math.h>
  3.  
  4. int main(void)
  5.  
  6. {
  7.  
  8.   double Population,capacity,initial;
  9.   int generations;
  10.   float result,growth;
  11.  
  12.  
  13.    printf("Please give the carrying capacity of the environment: ");
  14.    scanf("%lf", &capacity);
  15.  
  16.    printf("Please give the intrisic growth rate: ");
  17.    scanf("%f", &growth);
  18.  
  19.    result=exp (growth);
  20.  
  21.  
  22.    printf("Please give the inital population of the species: ");
  23.    scanf("%lf", &initial);
  24.  
  25.    printf("Please indicate the number of generations: ");
  26.    scanf("%d", &generations);
  27.  
  28.    Population=initial*result*(1-(initial/capacity));
  29.  
  30.     for(generations = 2; generations <=80; initial= Population)
  31.  
  32.        Population=initial*result*(1-(initial/capacity));
  33.  
  34.    printf("The expected population at the next generation is: %.6f\n",Population);
  35.    return(0);
  36.  
  37. }  
  38.  
Mar 13 '10 #1

✓ answered by whodgson

Convert population into a function
//then
population+=population();
BTW you should place you code in between code tags to make it easier for others to read.

2 1314
whodgson
542 512MB
Convert population into a function
//then
population+=population();
BTW you should place you code in between code tags to make it easier for others to read.
Mar 13 '10 #2
jkmyoung
2,057 Expert 2GB
The problem was that in your for loop you had:
Population=initial*result*(1-(initial/capacity));
You're using the initial variable over and over. You wanted:
Population=Population*result*(1-(initial/capacity)); or
Population*=result*(1-(initial/capacity));
Mar 15 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: multimatum2 | last post by:
Hello, I need to enable/disable input text forms... But... I need to have the same style (color...) in both modes.. Could you help me ? Thanx a lot A small sample... ...
9
by: kernelxu | last post by:
hi,everybody. I calling function setbuf() to change the characteristic of standsrd input buffer. some fragment of the progrem is: (DEV-C++2.9.9.2) #include <stdio.h> #include <stdlib.h> int...
15
by: Rob Nicholson | last post by:
I'm starting to worry a bit now. We're getting the above error when two users hit the same database/page on an ASP.NET application using ADO.NET, talking to a SQL 7 server. The error is perfectly...
2
by: pelletier.thomas | last post by:
Hello everybody. I'm trying to code a very little OS. But I have a problem with the keyboard input: It show thechar + "~" :s Can you help me ? The source is there :...
1
by: JWest46088 | last post by:
The program asks for the user to enter a real number and an imaginary number followed by another set of a real number and an imaginary number. It then takes those and adds them, subtracts them, and...
5
by: Kavya | last post by:
I saw these two ways for validating input First Way -------------- #include <iostream> #include <limits> using namespace std; int main() {
3
by: manxie | last post by:
Dear All Readers, I'm supposed to create a program with a switch and using voids to execute number of codes, that includes finding sum, average, maximum, and minimum, please read my code:...
13
by: cront | last post by:
I have a problem to work on: we will ask user to input anything and we will put that back onto the standard output with all set of brackets removed. We will not remove any single bracket e.g. ...
1
by: dwaterpolo | last post by:
Hi Everyone, I am trying to read two text files swY40p10t3ctw45.col.txt and solution.txt and compare them, the first text file has a bunch of values listed like: y y y y y y y
28
by: n00m | last post by:
Both codes below read the same huge(~35MB) text file. In the file 1000000 lines, the length of each line < 99 chars. Stable result: Python runs ~0.65s C : ~0.70s Any thoughts?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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...
0
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,...

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.