BarackObama's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
13 (0.02 per day)
Joined:
27-July 12
Profile Views:
1,463
Last Active:
User is offline Aug 05 2012 10:09 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   BarackObama has not set their status

Posts I've Made

  1. In Topic: Arrays and functions frustration plead

    Posted 31 Jul 2012

    Thank you Skydiver for all your teachings! I truly appriciate it
  2. In Topic: Arrays and functions frustration plead

    Posted 30 Jul 2012

    it displays the arrays as jumbled up numbers out of order. Im reading from a file to an 3 arrays how should I format it so that it knows when to read them appropriating into 3 arrays in respect to the data? like read the data untill it hits the other set of data and so forth untill its all filled up
  3. In Topic: Arrays and functions frustration plead

    Posted 30 Jul 2012

    So basically reading multiple arrays from a file with a format like this
    xxxx xxxxx xxxx
    xxxx xxxxx xxxx

    they are in 3 columns. Can anyone give me an example of how I can read the data into an array while distingusing the columns ? I preformed a loop storing 3 arrays but it didnt work.

    How can I make it so that it knows which columns to store the arrays?

    int readHousehold(ifstream &inFile,int idhouseholdArray[], double incomeArray[], int membersArray[],int size)
    52	{
    53	     int count = 0, rtnCode = 0;
    54	     int temp,temp2,temp3;
    55	      
    56	 
    57	     inFile >> temp >> temp2 >> temp3;
    58	     while ((!inFile.fail()) && (count < size))
    59	     {         
    60	        idhouseholdArray[count] = temp;
    61	        incomeArray[count] = temp2;
    62	        membersArray[count] = temp3;
    63	        count++;
    64	         
    65	 
    66	        inFile >> temp >> temp2 >> temp3;
    67	        if (count == size)
    68	        {
    69	           if (!inFile.fail())
    70	               rtnCode = 1;
    71	        }
    72	     }
    73	 
    74	     if (count < size)
    75	         rtnCode = 1;
    76	      
    77	     return rtnCode;
    78	}
    79	 
    80	 
    
  4. In Topic: Arrays and functions frustration plead

    Posted 29 Jul 2012

    This is the code I have so far, reading from the file to 3 seprate arrays is where im stuck. I tried fixing it but it still does work

    #include <iostream>
    #include <iomanip>
    #include <fstream>
    
    
    using namespace std;
    
    int readHousehold(ifstream &inFile,int idhouseholdArray[], double incomeArray[], int membersArray[], int size);
    void displayhouseData(int idhouseholdArray[], double incomeArray[], int membersArray[], int size);
    
    const int xx = 24;
    const int OK = 0;
    
    int main()
    {
      int rc;
      int size;
      
      int idhouseholdArray[xx]; 
      double incomeArray[xx];
      int membersArray[xx];
          
        ifstream inFile;                             // create an input file object
    
        cout << fixed
             << showpoint
    	   << setprecision(2);
    
        inFile.open("Bonus-Program.txt");                // open the file read
    
        if (!inFile.fail())                         // if open was successful
        {                                           // execute statements in true path
           rc = readHousehold(inFile, idhouseholdArray, incomeArray, membersArray, size);
            if (rc == OK) 
      	        displayhouseData(idhouseholdArray, incomeArray, membersArray, size);
            else
                cout << "Error: Incorrect house data in file!!\a" << endl;         
        }
        else                                        // if fail was not successful
        {                                           // execute statements in false path
            cout << "File \"bonus.txt\" "
                 << "not found."
                 << endl;
        }
    
    	system("PAUSE");
    
    	return 0;
    }
    
    int readHousehold(ifstream &inFile,int idhouseholdArray[], double incomeArray[], int membersArray[],int size)
    {
         int count = 0, rtnCode = 0;
         int temp,temp2,temp3;
         
    
         inFile >> temp >> temp2 >> temp3;
         while ((!inFile.fail()) && (count < size))
         {          
            idhouseholdArray[count] = temp;
            incomeArray[count] = temp2;
            membersArray[count] = temp3;
            count++;
            
    
            inFile >> temp >> temp2 >> temp3;
            if (count == size)
            {
               if (!inFile.fail()) 
                   rtnCode = 1;
            }
         }
    
         if (count < size)
             rtnCode = 1;
         
         return rtnCode;
    }
    
    
    void displayhouseData(int idhouseholdArray[], double incomeArray[], int membersArray[],int size)
    {
        for ( int idx = 0; idx < xx; idx++)
        cout << idhouseholdArray[idx];
        
        for ( int idxx = 0; idxx < xx; idxx++)
        cout << incomeArray[idxx];
        
        for ( int idxxx = 0; idxxx < xx; idxxx++)
        cout << membersArray[idxxx];
        
        
    }
    
    
  5. In Topic: Arrays and functions frustration plead

    Posted 29 Jul 2012

    Skydiver the file has three Columns of data and I have to store them into three arrays. the format is like this
    1041 12180 4
    1062 13240 3
    1327 19800 2
    1483 22458 8
    1900 17000 2
    2112 18125 7
    2345 15623 2
    3210 3200 3
    3600 6500 5
    3601 11970 2
    4724 8900 3
    6217 10000 2
    9280 6200 1
    1000 30000 3
    1200 35000 2
    5601 51970 9
    5724 66900 3
    5217 10000 2
    5280 70000 1
    5000 100000 6
    5200 25000 3
    5230 120000 6
    6641 85000 7
    7000 45500 4

    so I have to put them each row into an array. should I repeat a loop for each array by itself? How is is possible to read the data into an array separated like that?

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

BarackObama hasn't added any friends yet.

Comments

BarackObama has no profile comments yet. Why not say hello?