In: Computer Science
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.
Instructions
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 in the following format:
If the colonial model is the least price, output:
If the split-entry model is the least price, output:
If the single-story model is the least price, output:
If the colonial and split-entry models tie for the least price, output:
If the colonial and single-story models tie for the least price, output:
If the single-story and split-entry models tie for the least price, output:
Finally, if all three tie for the least price, output:
#include<bits/stdc++.h>
using namespace std;
int main()
{
float BasePrice;
float area;
vector<pair<float,float> >v;
int i;
string str;
for(i=0;i<3;i++)
{
cout<<"\nEnter base price of
"<<i+1<<" model = ";
cin>>BasePrice;
cout<<"Enter area square feet
of "<<i+1<<" model = ";
cin>>area;
v.push_back(make_pair(BasePrice,area));
}
for(i=0;i<3;i++)
{
cout<<v[i].first<<"\t"<<v[i].second<<endl;
}
cout<<endl;
if(v[0].first<v[1].first &&
v[0].first<v[2].first)
cout<<"The price per square foot of the colonial
model is the least.";
else if(v[1].first<v[0].first &&
v[1].first<v[2].first)
cout<<"The price per square foot of the
split-entry model is the least.";
else if(v[2].first<v[0].first &&
v[2].first<v[1].first)
cout<<"The price per square foot of the
single-story model is the least.";
else if(v[0].first==v[1].first &&
v[0].first==v[2].first)
cout<<"The price per square foot all three
models are the same.";
else if((v[0].first<=v[1].first &&
v[0].first<=v[2].first) || (v[1].first<=v[0].first &&
v[1].first<=v[2].first) || (v[2].first<=v[1].first &&
v[2].first<=v[0].first))
{
if(v[0].first==v[1].first
&& v[0].first<v[2].first)
cout<<"The price per square
foot of the colonial and split-entry models tie for the
least.";
else if(v[0].first<v[1].first
&& v[0].first==v[2].first)
cout<<"The price per square
foot of the colonial and single-story models tie for the
least.";
else if(v[1].first<v[0].first
&& v[1].first==v[2].first)
cout<<"The price per square
foot of the single-story and split-entry models tie for the
least.";
}
return 0;
}