Does not hold all list of input on Report

#include<iostream>
#include<string>
#include<fstream>

using namespace std;
void ReadFile(int property[], int bedroom[], double price[], int &count)
{
ifstream file("realestate.txt");
//Open ticketmastere text file.
if (file)
{
while (!file.eof())
{
file >> property[count];
file >> bedroom[count];
file >> price[count];
count++;
}
file.close();

cout << "File Opened ...." << endl;

}
else
{
cout << "File Cannot be Opened....." << endl;
}

}

void writeFile(int property[], int bedroom[], double price[], int count)
{
//writing the information back to the file
ofstream fileOut("realestate.txt");
fileOut << count;
for (int i = 0; i < count; i++)
{
fileOut << endl << property[i] << " " << bedroom[i] << " " << price[i];
}
fileOut.close();
}

void AddNewProperty(int property[], int bedroom[], double price[], int &count)
{
for (int i = 0; i < count; i++)
{

cout << "What is the property number between 1 to 20000? " << endl;
cin >> property[i];
if (property[i] < 1 || property[i] > 20000)
{
cout << "Error: Property Number cannot be less than 1 and more than 20000:" << endl;
break;
}

cout << "What is the price?" << endl;
cin >> price[i];
if (price[i] < 50000 || price[i] > 10000000)
{
cout << "Error: price cannot be lower than 50000 and more than 10000000" << endl;
break;
}
else
cout << "How many bedroom is it?" << endl;
cin >> bedroom[i];
if (bedroom[i] < 1)
{
cout << "Error: Bedroom cannot be lower than 1" << endl;
break;
}
else

{

cout << "New Property Successfully added " << endl;
break;
}

}
}

void PriceReduction(int property[], int bedroom[], double price[], int &count)
{
int propertyid;
double reductionamount=0;
cout << "Please Enter the property id:" << endl;
cin >> propertyid;
for (int i = 0; i < count; i++)
{
if (property[i] != propertyid)
{
cout << "Property " << propertyid << " does not exits " << endl;
}
else if (property[i] = propertyid)
{
cout << "please Enter the amout of reduction:" << endl;
cin >> reductionamount;
}
price[i] -= reductionamount;

}
}
void Searchproperty(int property[], int bedroom[], double price[], int &count)
{
double maximumprice = 0;
int minimumbedroom = 0;

cout << "Enter the Maximum Price: " << endl;
cin >> maximumprice;
cout << "Enter the Minimum Bedroom Needed: " << endl;
cin >> minimumbedroom;
for (int i = 0; i < count; i++)
{
if ((property[i] >= minimumbedroom) && (price[i] <= maximumprice))
{
cout << "The matched Property id: " << property[i] << " " << "Bedroom: " << bedroom[i] << " Price is: $" << price[i] << endl;
}

else
{
cout << "Sorry Not Available" << endl;
}
break;
}


}
void Report(int property[], int bedroom[], double price[], int count)
{
float avg;
int sum = 0;
for (int i = 0; i < count; i++)
{
cout << endl << "\Property ID:" << " " << property[i] << " " << "\Bedroom:" << " " << bedroom[i] << " " << "\Price:" << "$" << price[i] << endl;
sum += price[i];

}
avg = sum / count;
cout << "Average home price:" << "$" << avg << endl;

}

int main()
{
int property[20000]; // property[0],property[1]...property[19999]
double price[20000]; // price[0],price[1]...price[19999]
int bedroom[20000]; // bedroom[0],bedroom[1]...bedroom[19999]
int count = 0;
for (int i = 0; i < 20000; i++)
{
property[0] = 0;
price[0] = 0;
bedroom[0] = 0;
}

ReadFile(property, bedroom, price, count);

int choice = 1;
while (choice != 5)

{
// Step B: Create a Menu
cout << "REALTOR ASSIST v1.0 " << endl;
cout << "1-New Property" << endl;
cout << "2-Price Reduction" << endl;
cout << "3-Search Property" << endl;
cout << "4-Report" << endl;
cout << "5-Exit" << endl;

cout << "Please Enter your choice:";
cin >> choice;
if (choice == 1)
{
AddNewProperty(property, bedroom, price, count);
}

else if (choice == 2)
{
PriceReduction(property, bedroom, price, count);
}

else if (choice == 3)
{
Searchproperty(property, bedroom, price, count);
}
else if (choice == 4)
{
Report(property, bedroom, price, count);
}

else if (choice == 5)
{
break;
}


}
// write new info. into the file.
writeFile(property, bedroom, price, count);


system("pause");
return 0;
}
Last edited on
Topic archived. No new replies allowed.