Question #11264

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

// Q.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string>
#include<stdio.h>
using namespace std;
struct house{
string type;
float cost;
float squaremeter;
};

int main(){
house h[20];
int ch=0;
int coutnofhouse=0;
for(int i=0;i<3;i++){
printf("1 - Majestic
");
printf("2 - Split-entry
");
printf("3 - Single-story
");
printf("0 - Show information
");
printf("Select model: ");
scanf("%d",&ch);
switch(ch){
case 1:
h[coutnofhouse].type="Majestic";
break;
case 2:
h[coutnofhouse].type="Split-entry";
break;
case 3:
h[coutnofhouse].type="Single-story";
break;
}
printf("Enter the base price: ");
scanf("%f",&h[coutnofhouse].cost );
printf("Enter the finished area in square meters:
");
scanf("%f",&h[coutnofhouse].squaremeter);
coutnofhouse++;
}
printf("Model price per square meter
");
for(int i=0;i<3;i++){
printf("%s ",h[i].type.c_str());
printf("%.2f
",h[i].cost/h[i].squaremeter);
}
int i=0;
scanf("%d",i);

}
LATEST TUTORIALS
APPROVED BY CLIENTS