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

    Red face Infinite Loop

    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
    /* 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 ="<<<<"/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;
    int concentration(int &object1,int &object2){
        //Checks concentration between inside
        //and outside and changes accordingly
        if (object2>object1){
        int difference=object2-object1;
        }else if (object1>object2){
        int difference=object1-object2;
        int obj1=object1-(object1*2);
        int obj2=object2-(object2*2);
        if (object1<0||object2<0){
    int Rough_Endoplasmic_reticulum(int &water_in,int &carbon_in,int &oxygen_in){
    return 0;
    int vacuole(int data,int index){
    int information[20000];
    int nextindex=index++;
    return nextindex;
    int main(){
        srand((unsigned int);
        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 - 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

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


  3. #3
    Registered User
    Join Date
    Oct 2006
    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
    New Zealand
    Use srand like this:
    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-15-2011, 12:33 AM
  2. infinite loop
    By leahknowles in forum C Programming
    Replies: 4
    Last Post: 03-24-2011, 04: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, 12:17 PM
  4. Infinite Loop!!!
    By Frantic- in forum C++ Programming
    Replies: 3
    Last Post: 12-13-2004, 06:39 PM
  5. infinite while loop Q
    By Dragon227Slayer in forum C Programming
    Replies: 2
    Last Post: 11-21-2003, 09:53 AM

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