/* * worksheetEx.cpp * This program will get a number and if it is even, it will output the value from the input to 0 * and it will output 0 up to the input value if it's an odd num er * * Created by Shannon Steinfadt on 4/21/08. * * Completed by YOU on 4/23/08 */ #include // Library for input / output using namespace std; int main() // main function { int input, remainder; // Declare two integer variables cout << "Please enter a whole number: "; // Output prompt cin >> input; // Input the variable input remainder = input % 2; // Use the modulus function to find out if INPUT is even or odd cout << "The remainder is: " << remainder << endl; // Do two different things based on input being odd or even // if/else statement int i; // Create a new loop control variable if (remainder == 0) // if input is an even number (check remainder) { ///////////cout << "In the if statement\n"; i=input; // Assign the loop control variable to input while (i >= 0) // Loop while i is greater than zero { cout << i << " "; // Output the value of i i--; // Decrement i using the "--" operator } // End of loop } // End if (remainder == 0) else // remainder == 1, so it's an odd number { // Loop and output from 0 up to and including the input value ////////cout << "In the else / odd statement\n"; //i = 0; //while (i <= input) // Set up while so it runs from 0 up to and equal to the input value for(i=0; i <= input; i++) { cout << i << " "; // Oßutput the value of i // i++; // Increment i using the "++" operator } // End of loop } // End else where remainder == 1 cout << "\n\n"; return 0; }