3 Replies - 800 Views - Last Post: 21 October 2008 - 12:58 PM Rate Topic: -----

#1 StealthRT  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 29-September 08

While function to exit

Post icon  Posted 21 October 2008 - 10:58 AM

Hey all i am trying to get my code to work:
int main()
{
	float taxibleIncome = 0;
	float taxAmt = 0;
	int statusCode = NULL;

	while (statusCode != 9)
	{
		getStatusCode(statusCode);
		getTaxableIncome(taxibleIncome);
		calcTax(taxibleIncome, statusCode, taxAmt);
		displayTax(taxibleIncome, statusCode, taxAmt);
	}
	return 0;
}


The user have 1-4, 9 to choose from. If the user chooses 9 then the program needs to exit... but it doesn't matter since getStatusCode is inside the while loop... it will stay the same i know... but when i tried it outside the while loop i was never able to ask that question again without having it ask twice..
int main()
{
	float taxibleIncome = 0;
	float taxAmt = 0;
	int statusCode = NULL;

		getStatusCode(statusCode);

	while (statusCode != 9)
	{
		getStatusCode(statusCode);
		getTaxableIncome(taxibleIncome);
		calcTax(taxibleIncome, statusCode, taxAmt);
		displayTax(taxibleIncome, statusCode, taxAmt);
	}
	return 0;
}


And if i leave the getStatusCode out of the loop and keep the one outside the loop then the 2nd time around it doesnt ask the question.. it just goes and asks for the getTaxableIncome question...

Any ideas how i can do this?

David

Is This A Good Question/Topic? 0
  • +

Replies To: While function to exit

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: While function to exit

Posted 21 October 2008 - 11:04 AM

Where is your getStatusCode function? At first glance, you are sending a value to it...are you getting anything back? Do you mean to be sending that value by reference so you can modify it?
Was This Post Helpful? 0
  • +
  • -

#3 StealthRT  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 29-September 08

Re: While function to exit

Posted 21 October 2008 - 11:34 AM

View PostAmadeus, on 21 Oct, 2008 - 11:04 AM, said:

Where is your getStatusCode function? At first glance, you are sending a value to it...are you getting anything back? Do you mean to be sending that value by reference so you can modify it?


Amadeus: here is my code:
void getStatusCode(int&);
void getTaxableIncome(float&);
void calcTax(float, int, float&);
void displayTax(float, int&, float);

int main()
{
	float taxibleIncome = 0;
	float taxAmt = 0;
	int statusCode = NULL;

	getStatusCode(statusCode);
cout << statusCode << endl;
	while (statusCode != 9)
	{
		cout << statusCode << endl;
		getStatusCode(statusCode);
		getTaxableIncome(taxibleIncome);
		calcTax(taxibleIncome, statusCode, taxAmt);
		displayTax(taxibleIncome, statusCode, taxAmt);
	}
	return 0;
}

void getStatusCode(int& intCode)
{
	cout << "" << endl;
	cout << "You need to choose a number below for your filling status:" << endl;
	cout << "----------------------------------------------------------" << endl;
	cout << "(1) Single Filers" << endl;
	cout << "(2) Married Filing Jointly" << endl;
	cout << "(3) Married Filing Separately" << endl;
	cout << "(4) Head of Household" << endl;
	cout << "(9) Exit program" << endl;
	cout << "----------------------------------------------------------" << endl;
	cin >> intCode;

	return;
}


David
Was This Post Helpful? 0
  • +
  • -

#4 StealthRT  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 29-September 08

Re: While function to exit

Posted 21 October 2008 - 12:58 PM

Does this look ok?
int main()
{
	float taxibleIncome = 0;
	float taxAmt = 0;
	int statusCode = NULL;

	while (statusCode != 9)
	{
		getStatusCode(statusCode);
		statusCode = statusCode;

		if (statusCode == 9)
		{
			break;
		}

		getTaxableIncome(taxibleIncome);
		calcTax(taxibleIncome, statusCode, taxAmt);
		displayTax(taxibleIncome, statusCode, taxAmt);
	}
	return 0;
}


David
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1