I've read through all the other similar topic but unable to still find answer for mine. I've re-read my code and I don't see an issue. I've each if/is else statement in their own {} but I'm still only getting the first if expression statement output.
I've not totally new to programming but I'm new to C++.
In my comparison debugging I've done:
- if home is less than home 2 or home 3 ->> home < home2 || home3
- if home is less than home 2 and home 3 ->> home < home2 && home3
So I'm comparing price per sqft and output only the home with least price per sqft or if the price per sqft are the same between another home, then output that result. Changing || or && and vice versa and putting them in {} is still resulting in the same first if statement. I've even out the expression in ((...) || or && (...)) #include
using namespace std;
int main() {
// Write your main here
long colonialPrice, splitEntryPrice, singleStoryPrice;
double colonialArea, splitEntryArea, singleStoryArea;
double splitEntryModel = splitEntryPrice/splitEntryArea;
double colonialModel = splitEntryPrice/splitEntryArea;
double singleStoryModel = singleStoryPrice/singleStoryArea;
cout << "Enter base price for colonial model, split-entry, and single-story model >> ";
cin >> colonialPrice >> splitEntryPrice >> singleStoryPrice;
cout << endl;
cout <<"Enter finished area in sqft colonial model, split-entry, and single-story >> ";
cin >> colonialArea >> splitEntryArea >> singleStoryArea;
cout << endl;
//colonial model
if(colonialModel < splitEntryModel || singleStoryModel)
cout << "The price per square foot of the colonial model is the least" << endl;
else if(splitEntryModel < colonialModel || singleStoryModel)
cout << "The price per square foot of the split-entry model is the least" << endl;
else if (singleStoryModel< splitEntryPrice || colonialModel)
cout << "The price per square foot of the single-story model is the least" << endl;
else if (colonialModel == splitEntryModel)
cout << "The price per square foot of the colonial and split-entry models tie for the least." << endl;
else if(colonialModel == singleStoryModel)
cout << "The price per square foot of the colonial and single-story models tie for the least." << endl;
else if(singleStoryModel == splitEntryModel)
cout << "The price per square foot of the single-story and split-entry models tie for the least." << endl;
else if (colonialModel == singleStoryModel && splitEntryModel)
cout << "The price per square foot all three models are the same." << endl;
return 0;
}