/* Filename: HW2-ch.c*/ /* This program checks a number to see if it is even or odd.*\ /************************************************************************* * Programmer: Matthew Glynn * * Name: HW2-ch.c * * Engineering Problem Solving 2 * * Section: B36-Discussion, BBB-Lecture * * Assignment: Homework Number 2 * * Program: HW2-ch.c * * Description: This program checks a number to see if it is even or odd.* * ***********************************************************************/ /************************************************************************************ * The Pseudocode for challenge: * * * * 1 Ask someone to enter the amount of integer values to be entered * * * * 2 If a negative value is entered go to step ((2.5)), if not go to step ((3)) * * * * 2.5 Say please enter a positive number for the amount of values to be entered * * and if the number they enter is positive go to step 3, if it is negative, * * begin step 2.5 again * * * * * * 3 Ask someone to enter an integer value * * * * 4 Check if number is even or odd by seeing if the number has a remainder when * * it is divided by 2 * * * * If number even * * Display Number entered is even * * * * If number odd * * Display Number entered is odd * * * * 6 Keep doing this until you have reached the number of integer values requested * ************************************************************************************/ #include /*include the library stdio.h*/ int main( void )/* function main begins program execution*/ { /*this bracket starts the block for function main*/ int counter; /* a count for the while loop, set to a value of 1*/ int number; /* the number to be checked to see if it is even or odd */ /* initialization phase */ { /* This bracket starts the block that asks for the amount of integer values. */ printf("\nPlease enter the number of integer values to be entered: "); /*^^displays a statement on the screen that asks user to enter a number*/ scanf("%d", &counter); /* enters the counter value */ }/* This bracket ends the block that asks for the amount of integer values. */ /* This is the challenge part*/ while ( counter <=0) { /* starts while*/ printf("\nPlease enter a postive number!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n "); { /* question that asks for the amount of integer values. */ printf("\nPlease enter the number of integer values to be entered: "); /*^^displays a statement on the screen that asks user to enter a number*/ scanf("%d", &counter); /* enters the counter value */ }/* This bracket ends the block that asks for the amount of integer values. */ } /* ends while*/ while ( counter >0) /* initialize while loop for counter, until counter = 0*/ { /* This bracket is the start of the block for the while loop. */ printf("\nPlease enter an integer to see if it is even or odd: "); /*displays a statement on the screen that asks user to enter a number*/ /* processing phase */ scanf("%d", &number); /*^^^************************************************************** * scanf gives a user prompt so that the user can enter a value, * * that value is then put in memory as (number). * * * * ---Although the scanf function/statement has been declared * * by Microsoft to be deprecated "(In computer software standards * * and documentation, deprecation is the gradual phasing-out of * * a software or programming language feature.)," It remains * * widely implemented --- * ******************************************************************/ counter--; /* Decrease the counter by 1*/ if(number % 2) /*^^^^^^^^^^^************************************************************** * checks if number gives a remainder when divided by 2 by using the ( % )* * operator. This operator is known as the mudulus or remainder operator. * * This operatoris one of the multiplicative operators. * **************************************************************************/ { /* This bracket is the start of the block for if. */ printf("\nThe number %d is odd.\n\n", number); /*^^^************************************ * Display this result if number * * gives a remainder when divided by 2. * ****************************************/ } /* This bracket is the end of the block for if. */ else { /* This bracket is the start of the block for else. */ printf("\nThe number %d is even\n\n", number); /*^^^************************************* * Display this result if number does not* * gives a remainder when divided by 2. * *****************************************/ } /* This bracket is the end of the block for else. */ } /* end while loop */ /* termination phase */ /* The program will autimatically terminate once the counter has reached 0*/ return 0; /* indicate program ended successfully*/ } /*end function main*/ /************************************************************************* * Programmed by: Matt Glynn * *************************************************************************/