Program Keeps Crashing

Hi everybody,
I am working on an assignment but every time I run the program it crashes. When I build it I get no errors, Visual Studio just keeps telling me Assignment3.exe has stopped working. I This is the first time it happens to me and I cannot figure out the problem. Any help would be appreciated. This is what I have so far..

Header
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef HOUSELIST_H
#define	HOUSELIST_H
#include <string>

    struct House
{
    std::string streetAddress;
    std::string city; // Holds What City the House is Located in.
    int houseSize; // Holds Size of House
    double price; // Holds price of House
    int NumberOfBedrooms; // Hold number of bedrooms
};

//Houselist Class
class HouseList
{   
 private:
    House HouseInfo;

public:
    HouseList(); // Default Constructor
    
    //Set Functions
	void setStreetAddress(std::string sA)
    {HouseInfo.streetAddress = sA;}
    
    void setLocation(std::string cY)
    {HouseInfo.city = cY;}
    
    void setHouseSize(int hS)
    {HouseInfo.houseSize = hS;}
    
    void setPrice(double p)
    {HouseInfo.price = p;}
    
    void setNumBedrooms(int numBedRm)
    {HouseInfo.NumberOfBedrooms = numBedRm;}
    
    // Get Functions
    std::string getStreetAddress()
    {return HouseInfo.streetAddress;}
    
    std::string getLocation()
	{return HouseInfo.city;}
    
    int getHouseSize()
	{return HouseInfo.houseSize;}
    
    double getPrice()
	{return HouseInfo.price;}
    
    int getNumBedrooms()
	{return HouseInfo.NumberOfBedrooms;}
 };
#endif	/* HOUSELIST_H */ 


Houselist.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "Houselist.h"

//HouseList Constructor, Defaults
HouseList::HouseList()
    {
		HouseInfo.streetAddress = "Unknown";
		HouseInfo.city = "Unknown";
		HouseInfo.houseSize = 0;
		HouseInfo.price = 0;
		HouseInfo.NumberOfBedrooms = 0;
    }



Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "Houselist.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void readFromFiles(HouseList objArray[]);

int main()
{   
	HouseList object[20];

	readFromFiles(object);
	
	for (int j = 0; j <= 10; j++)
	{
		cout << object[j].getStreetAddress() << " " << object[j].getLocation() << " " << object[j].getHouseSize()
			 << object[j].getPrice() << " " << object[j].getNumBedrooms();
	}



	return 0;
}
void readFromFiles(HouseList objArray[])
{
	string address, city;
	int houseSize, numBeds, x = 0;
	double price;

	ifstream inFile;
   
	inFile.open("houseinfo.txt");
    if (!inFile)
        cout << "Error Opening File!.\n";
    else
    {
        while (!inFile.eof())
        {
			inFile >> address;
			inFile >> city;
			inFile >> houseSize;
			inFile >> price;
			inFile >> numBeds;
				
			objArray[x].setStreetAddress(address);
			objArray[x].setLocation(city);
			objArray[x].setHouseSize(houseSize);
		    objArray[x].setPrice(price);
			objArray[x].setNumBedrooms(numBeds);
			x++;
        }
       
    cout << endl;
    inFile.close();
    }
}


The houseinfo.txt file contains this information...just in case
1. 1002 Pecan st., McAllen, 2450, 210000, 5
2. 2402 Main st., McAllen, 1950, 179000, 4
3. 120 Sherry Ln., Mission, 3250, 450000, 6
4. 325 42th st., McAllen, 2050, 195000, 4
5. 2202 I Road, Pharr, 1450, 129500, 3
6. 10702 Sugar Rd., Edinburg, 2100, 205000, 4
> The houseinfo.txt file contains this information...just in case
> 1. 1002 Pecan st., McAllen, 2450, 210000, 5
> 2. 2402 Main st., McAllen, 1950, 179000, 4

Are these 1. 2. etc. also part of each line in the file?
Or are they just:
1002 Pecan st., McAllen, 2450, 210000, 5
2402 Main st., McAllen, 1950, 179000, 4
This code isn't doing what you think it's doing. Take a look at the values it reads from the files.
1
2
3
4
5
			inFile >> address;
			inFile >> city;
			inFile >> houseSize;
			inFile >> price;
			inFile >> numBeds;

Topic archived. No new replies allowed.