When you are doing 1 / num, num is an integer and thus you are doing integer division resulting in an integer value of 0 (assuming num = 4). If you want your program to calculate the actual value, num needs to be a float as well.
but when I change num to a float, it messes up this loop:
1 2 3 4 5
if(num % 2 == 0 && num > 0 && num != 0)
cout << "The number " << num << " is even!" << endl << endl;
else
cout << "The number is not a positive even number." << endl;
} while (num % 2 !=0 || num <=0);
Here we go! The reasons why the program wasn't working are as follows. First, when we declare that num1 = num2, what ever random value num2 had is stored in num1. This is not good! We need to declare num2 = num1 after we have defined what num1 is. Secondly, we need to do something with sum += incr; Since incr = .25, sum is going to be .25 + .25 + .25 + .25 = 1. Change sum += incr; to something more meaningful.
CSCE 1020 Lab 9 Randall Hall randallhall2@my.unt.edu
Enter an even number: 4
The number 4 is even!
20 20.25 20.5 20.75 21 The sum is 102.5
Process returned 0 (0x0) execution time : 1.314 s
Press any key to continue.
And by the way, haven't you guys ever heard about something called Debugging? Like step over, step into, step out, call stack, watches, breakpoints? None at all?