#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
const int ARRAY_PASSES = 100;
const int SIZE = 81;
char apartment[COUNT];
int count = 0;
double apartment_sq[SIZE], apartment_value[SIZE];
do
{
for (int COUNT = 0; COUNT <= ARRAY_PASSES; count++)
{
cout << "Please enter the name of the first apartment, or enter q to quit: \n";
cin.getline >> (apartment, SIZE);
cout << "Please enter the square footage of " << apartment[SIZE] << ": \n";
cin >> apartment_sq[COUNT];
cout << "Please enter the rent value of " << apartment_value[SIZE] << ": \n";
cin >> apartment_value[COUNT];
}
}
while (apartment != 1 || apartment_sq != 81 || apartment_value || 81);
That is being derived from this.#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
double apartment_sq_func(double, double);
double apartment2_sq_func(double, double);
double apartment3_sq_func(double, double);
double apartment4_sq_func(double, double);
int main()
{
int x= 0, count;
const int APARTMENT_ARRAY = 5;
double apartment_per_sq[APARTMENT_ARRAY];
double apartment_square[APARTMENT_ARRAY];
double apartment_value[APARTMENT_ARRAY];
double bed[APARTMENT_ARRAY];
double bath[APARTMENT_ARRAY];
const int SIZE = 81;
char
apartment_name[SIZE], apartment2_name[SIZE], apartment3_name[SIZE], apartment4_name[SIZE];
cout << "Please enter the name of first apartment: ";
cin.getline(apartment_name, SIZE);
cout << "Please enter the name of second apartment: ";
cin.getline(apartment2_name, SIZE);
cout << "Please enter the name of third apartment: ";
cin.getline(apartment3_name, SIZE);
cout << "Please enter the name of fourth apartment: ";
cin.getline(apartment4_name, SIZE);
for (count = 1; count < APARTMENT_ARRAY; count++)
{
do
{
if (count ==1)
{
cout << "Please enter the square footage of " << apartment_name << ": ";
}
else if (count == 2)
{
cout << "Please enter the square footage of " << apartment2_name << ": ";
}
else if (count == 3)
{
cout << "Please enter the square footage of " << apartment3_name << ": ";
}
else
{
cout << "Please enter the square footage of " << apartment4_name << ": ";
}
cin >> apartment_square[count];
x = 0;
while (apartment_square[count] <= 0)
{
cout << "Please enter a valid square footage greater than 0: ";
cin >> apartment_square[count];
}
if (count ==1)
{
cout << "Please enter the rent value of " << apartment_name << ": ";
}
else if (count == 2)
{
cout << "Please enter the rent value of " << apartment2_name << ": ";
}
else if (count == 3)
{
cout << "Please enter the rent value of " << apartment3_name << ": ";
}
else
{
cout << "Please enter the rent value of " << apartment4_name << ": ";
}
cin >> apartment_value[count];
while (apartment_value[count] <= 0)
{
cout << "Please enter a valid rent value greater than 0: ";
cin >> apartment_value[count];
}
if (count ==1)
{
cout << "Please enter the number of bedrooms for " << apartment_name << ": ";
}
else if (count == 2)
{
cout << "Please enter the number of bedrooms for " << apartment2_name << ": ";
}
else if (count == 3)
{
cout << "Please enter the number of bedrooms for " << apartment3_name << ": ";
}
else
{
cout << "Please enter the number of bedrooms for " << apartment4_name << ": ";
}
cin >> bed[count];
while (bed[count] <= 0)
{
cout << "Please enter a valid number of bedrooms greater than 0: ";
cin >> bed[count];
}
if (count ==1)
{
cout << "Please enter the number of bathrooms for " << apartment_name << ": ";
}
else if (count == 2)
{
cout << "Please enter the number of bathroooms for " << apartment2_name << ": ";
}
else if (count == 3)
{
cout << "Please enter the number of bathrooms for " << apartment3_name << ": ";
}
else
{
cout << "Please enter the number of bathrooms for " << apartment4_name << ": ";
}
cin >> bath[count];
while (bath[count] <= 0)
{
cout << "Please enter a valid number of bathrooms greater than 0: ";
cin >> bath[count];
}
x = 1;
} while (x < 1 );
}
apartment_per_sq[0] = apartment_sq_func(apartment_square[1], apartment_value[1]);
apartment_per_sq[1] = apartment2_sq_func(apartment_square[2], apartment_value[2]);
apartment_per_sq[2] = apartment3_sq_func(apartment_square[3], apartment_value[3]);
apartment_per_sq[3] = apartment4_sq_func(apartment_square[4], apartment_value[4]);
cout << left;
cout << setw(25);
cout << "Apartment Names" << setw(25) << "Value Per Sq. Foot" << "Bed / Bath\n";
cout << setw(25);
cout << setprecision(2);
cout << fixed << showpoint;
cout << apartment_name << "$ " << setw(20) << showpoint << setprecision(2) << apartment_per_sq[0];
cout << noshowpoint << setprecision(0) << bed[1] <<" Bed /" << bath[1] << " Bath" << endl;
cout << setw(25);
cout << apartment2_name << "$ " << setw(20) << showpoint << setprecision(2) << apartment_per_sq[1];
cout << noshowpoint << setprecision(0) << bed[2] << " Bed /" << bath[2] << " Bath" << endl;
cout << setw(25);
cout << apartment3_name << "$ " << setw(20) << showpoint << setprecision(2) << apartment_per_sq[2];
cout << noshowpoint << setprecision(0) << bed[3] << " Bed / " << bath[3] << " Bath" << endl;
cout << setw(25);
cout << apartment4_name << "$ " << setw(20) << showpoint << setprecision(2) << apartment_per_sq[3];
cout << noshowpoint << setprecision(0) << bed[4] << " Bed / " << bath[4] << " Bath" << endl;
}
double apartment_sq_func(double arg1, double arg2)
{
double answer;
answer = arg2 / arg1;
return answer;
}
double apartment2_sq_func(double arg1, double arg2)
{
double answer;
answer = arg2 / arg1;
return answer;
}
double apartment3_sq_func(double arg1, double arg2)
{
double answer;
answer = arg2 / arg1;
return answer;
}
double apartment4_sq_func(double arg1, double arg2)
{
double answer;
answer = arg2 / arg1;
return answer;
}
My attempt is to make the code more efficient by implementing better loops, as well as making it seemingly infinite in terms of entering data into the array. I just started about 3 weeks ago so I'm assuming I've made quite a few mistakes. If any of those could be pointed out as well I'd be grateful. I'm trying to learn as much as possible. I also know the code is a bit overboard for it's content. I'm just trying to implement as much as I can into a program to help burn into my brain what I've learned.-Thanks in advanced,
-spastic.
Edited by WingedPanther, 26 October 2011 - 05:42 AM.
add code tags (the # button)


Sign In
Create Account

Back to top









