C++: Samantha and Vikas are looking to buy a house in a new development. After l
ID: 640999 • Letter: C
Question
C++: Samantha and Vikas are looking to buy a house in a new development. After looking at various models, the three models they like are colonial, split-entry, and single-story. The builder gave them the base price and the finished area in square feet of the three models. They want to know the model(s) with the least price per square foot. Write a program that accepts as input the base price and the finished area in square feet of the three models. The program outputs the model(s) with the least price per square foot.
Explanation / Answer
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
double priceColonial;
double priceSplitEntry;
double priceSingleStory;
double finishedAreaColonial;
double finishedAreaSplitEntry;
double finishedAreaSingleStory;
double pricePerSquareFootColonial;
double pricePerSquareFootSplitEntry;
double pricePerSquareFootSingleStory;
string houseName;
cout << fixed << showpoint << setprecision(2);
cout << "Enter the price of colonial model: ";
cin >> priceColonial;
cout << endl;
cout << "Enter the finished area in square feet of colonial model: ";
cin >> finishedAreaColonial;
cout << endl;
pricePerSquareFootColonial = priceColonial / finishedAreaColonial;
cout << "Enter the price of split entry model: ";
cin >> priceSplitEntry;
cout << endl;
cout << "Enter the finished area in square feet of split entry model: ";
cin >> finishedAreaSplitEntry;
cout << endl;
pricePerSquareFootSplitEntry = priceSplitEntry / finishedAreaSplitEntry;
cout << "Enter the price of single story model: ";
cin >> priceSingleStory;
cout << endl;
cout << "Enter the finished area in square feet of single story model: ";
cin >> finishedAreaSingleStory;
cout << endl;
pricePerSquareFootSingleStory = priceSingleStory / finishedAreaSingleStory;
if (pricePerSquareFootColonial < pricePerSquareFootSplitEntry)
{
if (pricePerSquareFootColonial < pricePerSquareFootSingleStory)
cout << "The price per square foot of the colonial "
<< "model is the least." << endl;
else if (pricePerSquareFootColonial > pricePerSquareFootSingleStory)
cout << "The price per square foot of the single Story "
<< "model is the least." << endl;
else
cout << "The price per square foot of the colonial"
<< "model and the single story and are the same "
<< "but less the price per square foot of the "
<< "split entry model." << endl;
}
else if (pricePerSquareFootColonial > pricePerSquareFootSplitEntry)
{
if (pricePerSquareFootSplitEntry < pricePerSquareFootSingleStory)
cout << "The price per square foot of the split entry "
<< "model is the least." << endl;
else if (pricePerSquareFootSplitEntry > pricePerSquareFootSingleStory)
cout << "The price per square foot of the single story "
<< "model is the least." << endl;
else
cout << "The price per square foot of the split entry "
<< "model and the single story and are the same "
<< "but less the price per square foot of the "
<< "colonial model." << endl;
}
else
{
if (pricePerSquareFootColonial == pricePerSquareFootSingleStory)
cout << "The price per square foot all three "
<< "models are the same." << endl;
else if (pricePerSquareFootColonial > pricePerSquareFootSingleStory)
cout << "The price per square foot of the single story "
<< "model is the least." << endl;
else
cout << "The price per square foot of the colonial "
<< "model and the split entry model and are the same "
<< "but less the price per square foot of the "
<< "single story model." << endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.