ユーザが2つの住宅について同じ基本価格と平方フィートを入力する場合、2つのハウスタイプを出力する別のif/else文を作成するにはどうすればよいですか?すべての助けに感謝します。これを達成するためのif/else文の作成方法
#include using namespace std;
int main()
{
int baseColonial;
int baseSplit;
int baseSingle;
int sqftColonial;
int sqftSplit;
int sqftSingle;
int priceColonial;
int priceSplit;
int priceSingle;
cout << "Please enter the base price of the Colonial home: ";
cin >> baseColonial;
cout << "Now please enter the finished area in square feet: ";
cin >> sqftColonial;
cout << "Please enter the base price of the Split-entry home: ";
cin >> baseSplit;
cout << "Now please enter the finished area in square feet: ";
cin >> sqftSplit;
cout << "Please enter the base price of the Single-story home: ";
cin >> baseSingle;
cout << "Now please enter the finished area in square feet: ";
cin >> sqftSingle;
priceColonial = baseColonial/sqftColonial;
priceSplit = baseSplit/sqftSplit;
priceSingle = baseSingle/sqftSingle;
if ((priceColonial <= priceSplit) && (priceColonial <= priceSingle))
{
cout << endl << "The Colonial house is the cheapest." << endl;
}
else if ((priceSplit <= priceColonial) && (priceColonial >= priceSingle))
{
cout << endl << "The split-entry house is the cheapest." << endl;
}
else if ((priceSingle <= priceSplit) && (priceSplit >= priceColonial))
{
cout << endl << "The single-story house if the cheapest." << endl;
}
return 0;
私はすべての3平方フィートあたり同じ価格ですが、それが正常に機能していないシナリオでは、このコードを使用しようとしました。私は何が欠けていますか?他
場合((priceSingle == priceSplit)& &(priceSingle == priceColonial)) { coutの< <てendl < < "すべての3つの家のモデルは平方フィート当たり同じ価格を持っています。" < <エンド;あなたが> =と<仕事への最後のelse文のためだけに>または<にあなたの場合/他のif文で=の比較を変更する必要が
if (priceColonial < priceSplit) {
if (priceColonial < priceSingle) {
cout << endl << "The Colonial house is the cheapest." << endl;
}
else if(priceColonial == priceSingle) {
cout << endl << "The Colonial and Single-story houses are cheaper." << endl;
}
else {
cout << endl << "The Single-entry house is the cheapest." << endl;
}
}
else if(priceColonial == priceSplit) {
if (priceColonial < priceSingle) {
cout << endl << "The Colonial and Split-entry houses are cheaper." << endl;
}
else if(priceColonial == priceSingle) {
cout << endl << "All are of same price." << endl;
}
else {
cout << endl << "The Single-entry house is the cheapest." << endl;
}
}
else {
if (priceSplit < priceSingle) {
cout << endl << "The Split-entry house is the cheapest." << endl;
}
else if(priceSplit == priceSingle) {
cout << endl << "The Split-entry and Single-story houses are cheaper." << endl;
}
else {
cout << endl << "The Single-entry house is the cheapest." << endl;
}
}