This is my first time posting on here and I consider myself extremely new to C++. After the math is done, the program lets you know which is the least. Well, when total1, total2, and total3 are the same, the output is:
"The price per square foot of the colonial and split-entry models tie for the least".
and it is supposed to be:
"The price per square foot all three models are the same".
My program is showing no error, just the wrong output. I've searched this program online, but the answers are more than likely from a different level of C++ than what I am currently on. This question was posted a while back from someone else, but the answers are not the same as what I need to have display. Here is the instruction and what I got so far.
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:
The price per square foot of the colonial model is the least.
If the split-entry model is the least price, output:
The price per square foot of the split-entry model is the least.
If the single-story model is the least price, output:
The price per square foot of the single-story model is the least.
If the colonial and split-entry models tie for the least price, output:
The price per square foot of the colonial and split-entry models tie for the least.
If the colonial and single-story models tie for the least price, output:
The price per square foot of the colonial and single-story models tie for the least.
If the single-story and split-entry models tie for the least price, output:
The price per square foot of the single-story and split-entry models tie for the least.
Finally, if all three tie for the least price, output:
The price per square foot all three models are the same.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <iostream>
using namespace std;
int main() {
// Write your main here
double colonialBase, splitBase, singleBase;
double colonialSq, splitSq, singleSq;
double total1, total2, total3;
cout << "colonial base and sqft: ";
cin >> colonialBase >> colonialSq;
total1 = colonialBase / colonialSq;
cout << endl << endl;
cout << "split base and sqft: ";
cin >> splitBase >> splitSq;
total2 = splitBase / splitSq;
cout << endl << endl;
cout << "single base and sqft: ";
cin >> singleBase >> singleSq;
total3 = singleBase / singleSq;
cout << endl << endl;
if ((total1 < total2) && (total1 < total3))
cout << "The price per square foot of the colonial model is the least.";
else if ((total2 < total1) && (total2 < total3))
cout << "The price per square foot of the split-entry model is the least.";
else if ((total3 < total1) && (total3 < total2))
cout << "The price per square foot of the single-story model is the least.";
else if((total1 == total2) && ((total1 == total2) < total3))
cout << "The price per square foot of the colonial and split-entry models tie for the least.";
else if ((total1 == total3) && ((total1 == total3) < total2))
cout << "The price per square foot of the colonial and single-story models tie for the least.";
else if ((total2 == total3) && ((total2 == total3) < total1))
cout << "The price per square foot of the single-story and split-entry models tie for the least.";
else
if ((total1 == total2) && (total2 == total3) && (total1 == total3))
cout << "The price per square foot all three models are the same";
return 0;
}
|
I'm not expecting anyone to reformat this for me. I just want to know why I am not getting the results I need. Thanks.