I don't follow. What do you mean?Originally Posted by Epo
I don't follow. What do you mean?Originally Posted by Epo
He is saying that if you use pointer in the function you have to pass the adress of the variable you are passing to the function or it will give you an error, because pointers only store the adress of the value.Originally Posted by MyntiFresh
Your function prototype for menu is:
However, it is:Code:void menu(char&, int&, int&, int&, int&); //I don't know what this does...
That means you are taking a pointer as a parameter.Code:void menu(char*, int*, int*, int*, int*); //Here you are taking pointers
Then, when you call the menu function:
Must be:Code:menu(operation, numeratorOne, denominatorOne, numeratorTwo, denominatorTwo);
Which will pass the address of each variable into your function.Code:menu(&operation, &numeratorOne, &denominatorOne, &numeratorTwo, &denominatorTwo);
Then, inside your menu() function, you can use:
Which will alter the value located at the address which operation is pointing to.Code:cin >> (*operation); //Brackets not necessary
Will change the address which operation points to, which will not only lead to crazy things happening probably, but definitely not your desired outcome.Code:cin >> (operation); //Brackets not necessary
Pointers are a tricky topic. Give it a read over. www.eternallyconfuzzled.com (Prelude's website) has a great tutorial on pointers, as does the FAQ here on the boards. If you haven't been using pointers long, then they're a great resource. If you have, perhaps a quick refresher could help out.
Pentium 4 - 2.0GHz, 512MB RAM
NVIDIA GeForce4 MX 440
WinXP
Visual Studio .Net 2003
DX9 October 2004 Update (R.I.P. VC++ 6.0 Compatability)
I haven't learned pointers yet, so I don't know what to do. Everything in the program runs fine... I just can't figure out now that I have the menu looping, how do I make it so that the program exits if the user inputs 'x' or 'X'???
Have the x case either exit(0); or return 0;
Just a quick suggestion.
Thanks... I've done that and it works.... but I don't want the program to continue getting numbers. What the program is doing now is when i input 'x' it still asks me for the numbers, then once I've entered them the program terminates. Suggestions?Originally Posted by JoshR
That will exit the program and it won't continue.
Hmm so I suspect the problem you speak of resides in your menu function...Have the menu function check for x, if x is present then quit.
Thanks. I got it now!
These are what're known as references. It's C++'s attempt at a "better" pointer. Personally I don't like them. At any rate, this is how it works:Originally Posted by Epo
It's in effect as if you had used a pointer, without the "hassle" of indirection. There's a few other points, such as, you can never have a null reference. Thus, if you have something that could potentially be null, you can't use a reference for it.Code:void foo( int &bar ) { bar = 10; } int main ( ) { int baz = 5; foo( baz ); ...baz now equals 10... return 0; }
Quzah.
Hope is the first step on the road to disappointment.
Oh...well...pretty much everything I've suggested is wrong then...my bad...and I was wondering how the rest of the program was working...I guess that explains it.
I think I'm gonna be agreeing with you on this. It seems like an attempt to re-work something that already works. I dunno, maybe I'm just too used to pointers.Personally I don't like them.
I've never seen references before (I just assumed "by reference" meant pointers), thanks for the info Quzah.
Pentium 4 - 2.0GHz, 512MB RAM
NVIDIA GeForce4 MX 440
WinXP
Visual Studio .Net 2003
DX9 October 2004 Update (R.I.P. VC++ 6.0 Compatability)