I am trying to make a program for class which is circular so it can be used until the user is done. the idea is choose an option then it calls the function, but for some reason it calls the estimate screen even when main_input does not equal 2. I know this is a newbie question, I'm still very much learning. Can someone help?

void Main_Screen::main_screen()
{
	cout<< "MAIN SCREEN" <<endl;
	cout<< "Enter the number to the left of your option." <<endl;
	cout<< "1) Customer Information" <<endl;
	cout<< "2) Estimate Calculation" <<endl;
	cout<< "0) Close Cleaner" <<endl;
}



void Estimate::estimate_screen()
{
	while (estimate_input != 0)
	{
	cout<< "ESTIMATE CREATION" <<endl;
	cout<< "What would you like to do?" <<endl;
	cout<< "1)Create an estimate" <<endl;
	cout<< "2)Change variables" <<endl;
	cout<< "0)Leave estimate creation" <<endl;
	cin>> estimate_input;
	}
}
int main()
{
	int main_input = 4;
	Intro a1;
	Main_Screen a2;
	Estimate a3;
	
	a1.main_print();
	
	while (main_input > 0)
	{
	a2.main_screen();
	cin>> main_input;
	
	if (main_input = 2) a3.Estimate::estimate_screen();
	}
	
	

}

Well, at a quick glance your if statment seems off. You have a "="..which is for assigning. Might want a "==". Not sure if that's you're only prob. But start with that

Thankyou SOOOO much. Both of you. I knew it was rookie mistake. :)

I'm getting garbage out of this function as well. Any ideas?

class Estimate
{
private:
	int distance, total;
public:
	void estimate_screen();
};


        void Estimate::estimate_screen()
        {
	int const charge = 1;
	int area=0, fee=0, misc=0, gas_fee1 = 10, gas_fee2 = 15;

	cout<< "ESTIMATE CREATION" <<endl;
	cout<< "How many miles will you be traveling?";
	cin>> distance;
	if (distance < 15) total = total + gas_fee1;
	if (distance > 14) total = total + gas_fee2;
	cout<< "How many square feet is the area to be cleaned?";
	cin>> area;
	fee = area * charge;
	total = total + fee;
	cout<< "Are there any extra fees?";
	cin>> misc;
	total = total + misc;
	cout<< "Your estimate is" <<total<< ".";

You're not initializing total. It's going to be garbage unless you set it to the identity for addition before you start adding to it.

Also I'm not sure your logic is sound at lines 18 and 19.
Wouldn't something like this make more sense?

if (distance < 15)
    total += gas_fee1;
else
    total += gass_fee2;

This is assuming you aren't using gas_fee as a unit cost for 1 distance traveled, which makes more sense to me.

-Vance

@enkidu75 please do not mark your posts as CODE SNIPPETS, this option is designer for people to posts and share working code and not for posting questions. Leave it to default FORUM THREAD.
Edited, now it is forum thread as is supposed to be.

This article has been dead for over six months. Start a new discussion instead.