#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int odd(int nValue)
{
nValue= nValue -1;
return nValue;
}
int main()
{
int nValue;
cout << "Enter a Positive Number: ";
cin >> nValue;
while ((nValue>2) && (nValue % 2 == 0))
{
nValue = nValue -2;
cout << nValue <<endl;
}
while (nValue>2)
{
nValue = odd(nValue);
if(nValue % 2 == 0)
{
//nValue = nValue -2;
cout << nValue <<endl;
}
}
system("pause");
return 0;
}
Why does the above program work?
when in the second while loop i have
//nValue = nValue -2;
Where when its not it counts down by 4. I cant see the way the flow structure in my program works.
Write a program that prompts the user for a positive number and uses a repetition control structure to print every even number less than the number and greater than zero (0) in reverse order. For example, if the user enters 19, the numbers 18, 16, 14, 12, 10, 8, 6, 4 and 2 are printed.