In: Computer Science
C++ language
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:
C++ code:
#include <iostream>
using namespace std;
int main() {
cout<<"Enter the square feet area of various
models and their base prices:"<<endl;
float f1,f2,f3;
float bprice1,bprice2,bprice3;
float fprice1,fprice2,fprice3;
cout<<"Enter the base price for colonial
model:";
cin>>bprice1;
cout<<"Enter the square feet area of colonial
model:";
cin>>f1;
fprice1 = f1/bprice1;
cout<<"Enter the base price for split-entry
model:";
cin>>bprice2;
cout<<"Enter the square feet area of split-entry
model:";
cin>>f2;
fprice2 = f2/bprice2;
cout<<"Enter the base price for single-story model:";
cin>>bprice3;
cout<<"Enter the square feet area of
single-story model:";
cin>>f3;
fprice3 = f3/bprice3;
if(fprice1==fprice2 && fprice1==fprice3)
{
cout<<"The price per square foot all the three
models are same";
}
else if(fprice1==fprice2 &&
fprice1<fprice3)
{
cout<<"The price per square foot for colonial
and split-entry models tie for the least";
}
else if(fprice1==fprice3 &&
fprice1<fprice2)
{
cout<<"The price per square foot for colonial
and single-story models tie for the least";
}
else if(fprice2==fprice3 &&
fprice2<fprice1)
{
cout<<"The price per square foot for split-entry
and single-story models tie for the least";
}
else if(fprice1<fprice2 &&
fprice1<fprice3)
{
cout<<"The price per square foot of the colonial
model is the least";
}
else if(fprice2<fprice1 &&
fprice2<fprice3)
{
cout<<"The price per square foot of the
split-entry model is the least";
}
else if(fprice3<fprice1 &&
fprice3<fprice2)
{
cout<<"The price per square foot of the
single-story model is the least";
}
return 0;
}
Execution screenshot: