Can't get this to work D:

Hi
I'm trying to figure out how to get this program to output the models with the least price.But it keeps showing numbers instead.

I'm still a beginner at this so the code might look really weird.



#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
        int mjc, s_entry, s_story, baseprice, f_area, cheapest, bpmjc, bpsentry, bpsstory;

        bpmjc = baseprice/mjc;
        bpsentry = baseprice / s_entry;
        bpsstory = baseprice / s_story;
             
        cout<<"Enter the base price: ";
        cin>>baseprice;
        
        cout<<"Enter the finished area of the Majestic house: ";
        cin>>mjc;
        
        
        cout<<"Enter the finished area of the Split Entry house: ";
        cin>>s_entry;
        
        
        
        cout<<"Enter the finished area of the Single Story house: ";
        cin>>s_story;
        
        cout<<"The price for the majestic house per square meter is : "<<baseprice / mjc<<endl;
        
        cout<<"The price for the Split Entry house per square meter is : "<<baseprice / s_entry<<endl;
        
        cout<<"The price for the Single Story house per square meter is : "<<baseprice / s_story<<endl;
        

        
        
        cout<<"Enter the number per square feet for the Majestic house : ";
        cin>>bpmjc>>bpsentry>>bpsstory;
        
        if (bpmjc > bpsentry && bpmjc > bpsstory)
           cheapest = bpmjc;
        
        if (bpsentry > bpmjc && bpsentry > bpsstory)
           cheapest = bpsentry;
        
        if (bpsstory>bpmjc && bpsstory > bpsentry)
           cheapest = bpsstory;
        
        cout<<"Therefore,the model with the least price per square meter is "<<cheapest<<endl;
        
        
        system("pause");
        return 0;
        
        
        
}
You uses uninitialized variables in the code

1
2
3
        bpmjc = baseprice/mjc;
        bpsentry = baseprice / s_entry;
        bpsstory = baseprice / s_story;


So their values have some memory garbage.
Topic archived. No new replies allowed.