Take a look at your
Addition() function:
34 35 36 37 38 39 40 41
|
void Addition()
{
int choice=0,x,y,ans,r=0,w=0;
char cont;
if (choice == 1)
{
// ...
|
You initialize
choice to 0 and then you immediately check if it's equal to 1.
Of course it's not going to be equal to 1 (because you just set it to 0), so that entire block never runs.
The important thing(s) to realize here is:
1. Your
choice variable does not "carry over" from
main(). The
choice variable in
Addition() is completely different and separate from the one in
main().
2. Because of your
switch
statement in
main() (lines 17-21), the only way
Addition() will ever get called is if the user enters 1, so there's no need to check for
choice == 1
anymore in
Addition() because that's the only way
Addition() could have gotten called in the first place.
That being said, the fix is to remove the
if (choice == 1)
check in line 39 of
Addition() (and you have the same problem with your
Subtraction() function as well).
By the way, you also have a problem with your loops. No matter what I enter when it says "Continue(y/n)? ", it always runs exactly twice.
One way to fix that would be to change
for (int j = 1; j <= 2; ++j)
(line 42)
to
while (cont == 'y')
(But also initialize
cont to
'y'
on line 36 -- or, better yet, make it into a
do
-
while
loop)
and then change your
if (x + y == ans)
check to
48 49 50 51 52 53 54 55 56 57
|
if (x + y == ans)
{
cout << "\t Correct\n"; r++;
}
else
{
cout << "\t Wrong\n"; w++;
}
cout << "\tContinue(y/n)? ";
cin >> cont;
|
200!