Feb 27, 2011 at 3:39pm UTC
i really need some helop here guys. heres the deal; i need the numbers re-entered in my bool function to overwrite the ones entered in the main function. the bool function is called upon only when the numbers entered in main are invalid. heres some of the code...
cout << "Enter fraction x: ";
cin >> num1 >> slash >> denom1;
'\n';
cout << "Enter fraction y: ";
cin >> num2 >> slash >> denom2;
boolFunction (num1, num2, denom1, denom 2, slash);
.................
.....................
.................
..............
now here is the function:
bool boolfunction(int num1, int denom1, int num2, int denom2, char slash)
{
if ( slash == '/' && denom1 != 0 && denom2 != 0)
return true;
else
{
cout << "Invalid entry, please re-enterFractions:
\n";
cout << "Enter fraction x: ";
cin >> num1 >> slash >> denom1;
'\n';
cout << "Enter fraction y: ";
cin >> num2 >> slash >> denom2;
return false;
}
i need the numbers reentered in the function to return to main and overwrite the ones previosly.
any suggestions?
Feb 27, 2011 at 4:24pm UTC
When posting code snippets, please put them inside code tags. It makes the post more legible, making it more likely that you will get a response.
The way to change the value of a callers variables is to take the arguments by reference:
bool boolfunction(int & num1, int & denom1, int & num2, int & denom2, char slash)