Hi, I've just looked at your code. Firstly,
could you please use code tags so that you code will be more readable! [ code ] //your code [ /code ] becomes
//your code
.
You loop behavior seems to be fine, I've just looped through your application several times before keying in 5 to exit. Having said that your code does contain a few oddities.
One problem stems from the use of
getline(...)
. When you use at your first
cin
statement, whatever value you read in, for example "
1" when you press the Enter key, the value one is taken and stored in the appropriate variable (
in this case choice
).
As the
Enter (
or Return) key is also a type of character
it remains on the stream, then this is consumed by the first
getline(...)
call. That's why
frac1
is always empty.
You can solve this by using
cin
instead of
getline(...)
.
zhar999 wrote: |
---|
void main() |
Use of the
void main()
prototype is not good practice in C++. You should use:
1 2 3 4 5 6
|
int main()
{
//your code
return 0;
}
|
Inside your
case
statement you have an additional
cin
which is completely pointless, as when you loop again, you are asked to re-enter your "choice".
Lastly
void addition(fraction, fraction);
I've seen these kinds of function prototypes before and it always surprises me that it compiles. I can't really comment much on it other than the fact that I would
avoid these kinds of prototypes as you cannot tell what the
data type is, but whether you take this onboard is your choice (
see what I did there).
Oh also (
I've only just noticed), the function prototype
void addition(fraction, fraction);
and the function definition
void addition(fraction num1, fraction num2)
do not match. I'm pretty sure the compiler will treat them as different functions. Although I'm not quite sure if that was intended...
I hope this helps.