Thread: Keeping track of values without an array

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    33

    Keeping track of values without an array

    In the function below, how can I keep track of factors. For every factor how could I store as a variable so that I can reference it later. The problem I have now is that every loop the value will change, so I will delete every factor and the variable will end up being the last factor, if any. Is there anyway to do this without an array or stuff covered in the second half of intro. computing courses?



    Code:
    void factorevaluation(int n)
    {    
    
    int count;
        count=2;
       storefactor1;
        
        
      
        while(count <= (n/2))
        {
         if (n%count==0)
         storefactor1=count;
         count++;
        }
      
    }
    sorry about that
    Last edited by m712; 11-07-2002 at 01:49 AM.

  2. #2
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    edit your post so you have [/code] as the bottom tag not simplay [code].

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    No. Of course not. Your only option is to use an array, write them to a file for later analysis, or just print the values as they come down the pike. What else did you expect
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >What else did you expect
    magically_store_values_without_an_array() by including <iwish.h> of course.

    >Is there anyway to do this without an array or stuff covered in the second half of intro. computing courses?
    Make a bunch of variables to take the place of an array.

    -Prelude
    My best code is written with the delete key.

  5. #5
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    can't you just output each time the loop goes through before it goes again? kind of the same idea as:

    Code:
    for (int count = 1; count <=50; ++count)
    {
    cout<<"Count is "<<count<<". \n";
    }
    That would output 1 - 50.

    Code:
    void factorevaluation(int n)
    {    
    
    int count = 2;
       
       storefactor1;
        
        
      
        while(count <= (n/2))
        {
         if (n%count==0)
         storefactor1=count;
         cout<<storefactor1<<"\n";
         count++;
        }
      
    }
    Last edited by RoD; 11-07-2002 at 10:33 AM.

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    yes you can, but if all you do is just output it to the screen you can't go back later and retrieve a particular value. You could write each value to a file in addition to/instead of writing to the screen, and then read/write to file as needed to avoid using an array (or some other container), but that's it. The stuff is either stored in memory somewhere(fast RAM memory using a container within the program, or slow memory using a file someplace), outputting to some device (screen, printer, whatever), or ignoring whatever comes down the pike.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Storing values from Edit Box into an array
    By E_I_S in forum C++ Programming
    Replies: 10
    Last Post: 06-05-2008, 06:24 AM
  2. keeping track of values
    By marquis1431 in forum C Programming
    Replies: 3
    Last Post: 04-09-2008, 07:52 PM
  3. Eliminating duplicate values from a 20x2 array
    By desipunjabi in forum C Programming
    Replies: 2
    Last Post: 10-29-2005, 09:11 PM
  4. Converting Char Array Loop values to integer
    By azamsharp1 in forum C Programming
    Replies: 8
    Last Post: 10-27-2005, 09:13 AM
  5. 3-d array assign string values
    By WaterNut in forum C++ Programming
    Replies: 8
    Last Post: 07-01-2004, 12:02 AM