# Answer to Question #25061 in C++ for ahmed

Question #25061

Assume you are looking to buy a house in a new development. After looking at various models, the three models they like are majestic, split-entry, and single-story.The builder gave them the base price and the finished area in square meters of three models. They want to know the model(s) with the least price per square feet. Write a program that accepts as input the base price and the finished area in square meters of the three models. The program outputs the model(s) with the least price per square meter.

Expert's answer

#include <iostream>

#include <conio.h>

using namespace std;

float find_lowest_cost_models(float* basePrice, float* finishedArea,

bool* leastPriceModels, int modelCount)

{

float theLeastPrice = basePrice[0] / finishedArea[0];

float tmp;

/* Find the model with the least price per square feet */

for (short t = 1; t < modelCount; t++)

{

tmp = basePrice[t] / finishedArea[t];

if (tmp < theLeastPrice)

theLeastPrice = tmp;

}

for (short g = 0; g < modelCount; g++)

if (basePrice[g] / finishedArea[g] == theLeastPrice)

leastPriceModels[g] = true;

return theLeastPrice;

}

int main()

{

float basePrice[3];

float finishedArea[3];

bool leastPriceModels[3] = { false };

float lowestPrice;

for (short c = 1; c <= 3; c++)

{

cout << "Enter the base price of the model #" << c << ": ";

cin >> basePrice[c - 1];

cout << "Enter the finished area of the model #" << c << ": ";

cin >> finishedArea[c - 1];

cout << endl;

}

lowestPrice = find_lowest_cost_models(basePrice, finishedArea, leastPriceModels, 3);

cout << endl;

for (short y = 0; y < 3; y++)

if (leastPriceModels[y])

cout << "The model #" << y + 1

<< " with the lowest price per square meter of "

<< lowestPrice << "." << endl;

_getch();

return 0;

}

#include <conio.h>

using namespace std;

float find_lowest_cost_models(float* basePrice, float* finishedArea,

bool* leastPriceModels, int modelCount)

{

float theLeastPrice = basePrice[0] / finishedArea[0];

float tmp;

/* Find the model with the least price per square feet */

for (short t = 1; t < modelCount; t++)

{

tmp = basePrice[t] / finishedArea[t];

if (tmp < theLeastPrice)

theLeastPrice = tmp;

}

for (short g = 0; g < modelCount; g++)

if (basePrice[g] / finishedArea[g] == theLeastPrice)

leastPriceModels[g] = true;

return theLeastPrice;

}

int main()

{

float basePrice[3];

float finishedArea[3];

bool leastPriceModels[3] = { false };

float lowestPrice;

for (short c = 1; c <= 3; c++)

{

cout << "Enter the base price of the model #" << c << ": ";

cin >> basePrice[c - 1];

cout << "Enter the finished area of the model #" << c << ": ";

cin >> finishedArea[c - 1];

cout << endl;

}

lowestPrice = find_lowest_cost_models(basePrice, finishedArea, leastPriceModels, 3);

cout << endl;

for (short y = 0; y < 3; y++)

if (leastPriceModels[y])

cout << "The model #" << y + 1

<< " with the lowest price per square meter of "

<< lowestPrice << "." << endl;

_getch();

return 0;

}

## Comments

## Leave a comment