Infinite Loop

This is a discussion on Infinite Loop within the C++ Programming forums, part of the General Programming Boards category; Hi, I have been busy trying out a program which emulates the basic functions of a cell( well presently only ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    1

    Red face Infinite Loop

    Hi,
    I have been busy trying out a program which emulates the basic functions of a cell( well presently only one basic function) but i have run into a hitch. The program doesn't display my output! and i don't understand why, any help is appreciated
    Code:
    /* By Himanshu Goel
       18 April 2012
    
    
    Cell Algorithm
        An algorithm designed to mimic the activity of any single cell
        through the use of basic functions of any cell converted into
        computer functions
    */
    
    
    
    
    #include <iostream>
    #include <cstdlib>
    #include <stdio.h>
    #include <math.h>
    
    
    
    
    #define Ribosome 101
    #define Golgi_App 111
    #define Mitochondria 001
    #define Plasma_Mem 011
    
    
    
    
    using namespace std;
    
    
    
    
    
    
    
    
    
    
    struct cell{
        int energy;
        int oxygen_in;
        int oxygen_out;
        int carbon_di_in;
        int carbon_di_out;
        int water_in;
        int water_out;
        int protiens;
        int dead;
    };
    cell head;
    
    
        int High=100;
        int Low=0;
    int dead(){
    cout<<"The Cell has died due to defficiency of resources";
    cout<<"/n Energy ="<<head.energy<<"/n O2 inside the cell = "<<head.oxygen_in;
    cout<<"/n O2 outside the cell = "<<head.oxygen_out;
    cout<<"/n CO2 inside the cell = "<<head.carbon_di_in;
    cout<<"/n CO2 outside the cell = "<<head.carbon_di_out;
    cout<<"/n Water inside the cell = "<<head.water_in;
    cout<<"/n Water outside the cell = "<<head.water_out;
    cout<<"/n The number of protiens produced is "<<head.protiens;
    head.dead=12;
    }
    
    
    
    
    int concentration(int &object1,int &object2){
        //Checks concentration between inside
        //and outside and changes accordingly
        if (object2>object1){
        int difference=object2-object1;
        object1+=difference;
        object2-=difference;
        }else if (object1>object2){
        int difference=object1-object2;
        object2+=difference;
        object1-=difference;
        }
        int obj1=object1-(object1*2);
        int obj2=object2-(object2*2);
        if (object1<0||object2<0){
        dead();}
        }
    
    
    
    
    int Rough_Endoplasmic_reticulum(int &water_in,int &carbon_in,int &oxygen_in){
    water_in-=1;
    concentration(water_in,head.water_out);
    carbon_in+=1;
    concentration(carbon_in,head.carbon_di_out);
    oxygen_in-=1;
    concentration(oxygen_in,head.oxygen_out);
    head.protiens++;
    return 0;
    }
    
    
    int vacuole(int data,int index){
    
    
    int information[20000];
    information[index]=data;
    int nextindex=index++;
    return nextindex;
    
    
    }
    
    
    
    
    int main(){
        srand((unsigned int) head.energy);
        srand((unsigned int) head.oxygen_in);
        srand((unsigned int) head.oxygen_out);
        srand((unsigned int) head.carbon_di_in);
        srand((unsigned int) head.carbon_di_out);
        srand((unsigned int) head.water_in);
        srand((unsigned int) head.water_out);
    
    
        //assign random values to the variables
        head.energy=rand()%(High - Low + 1)+ Low;
    
    
        head.oxygen_in=rand()%(High - Low + 1)+ Low;
        head.oxygen_out=rand()%(High - Low + 1)+ Low;
    
    
        head.carbon_di_in=rand()%(High - Low + 1)+ Low;
        head.carbon_di_out=rand()%(High - Low + 1)+ Low;
    
    
    
    
    
    
    
    
        head.water_in=rand()%(High - Low + 1)+ Low;
        head.water_out=rand()%(High - Low + 1)+ Low;
    
    
    while (1){ Rough_Endoplasmic_reticulum(head.water_in,head.carbon_di_in,head.oxygen_in);
    if (head.dead=12){break;}
    }
    }

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,145
    O_o

    An offhand guess says that you aren't ever actually calling any routines which dump any output.

    Soma

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    2,266
    don't call srand() more than once. only the last call will have an effect anyway. also, your formatting could use some work. try to be consistent with bracket placement and indentation.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,288
    Use srand like this:
    Code:
    srand(time(0));
    That's all.
    Make sure you leave that at the top of your main so it will only be called once.

    Please look up and learn about nice indentation of code. The compiler may not care too much about where whitespace goes, but we do! We need to be able to read it very easily. If it's at all difficult to read, some percentage of readers will just not bother trying to help.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 10-14-2011, 11:33 PM
  2. infinite loop
    By leahknowles in forum C Programming
    Replies: 4
    Last Post: 03-24-2011, 03:37 PM
  3. stays in loop, but it's not an infinite loop (C++)
    By Berticus in forum C++ Programming
    Replies: 8
    Last Post: 07-19-2005, 11:17 AM
  4. Infinite Loop!!!
    By Frantic- in forum C++ Programming
    Replies: 3
    Last Post: 12-13-2004, 05:39 PM
  5. infinite while loop Q
    By Dragon227Slayer in forum C Programming
    Replies: 2
    Last Post: 11-21-2003, 08:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21