Home | | Schedule | | Assignments | | Lectures | | Resources
//***********************************************************************
// even.cc
// Author: King/Royden
// Date: February 10, 2014
// Class: CSCI 131
// Purpose: This program determines if a number is even, odd or zero
// Input: (from standard input) a single digit number (0..9)
// Output: (to standard output) a message indicating that the number
// was ZERO, EVEN, or ODD
//***********************************************************************
#include <iostream>
using namespace std;
int main( void )
{
char ch; // The input digit is stored as a character
cout << "Enter a single digit number (between 0 and 9): ";
cin >> ch;
cout << ch << endl;
switch (ch) {
case '0' : cout << "You entered a ZERO..." << endl;
break;
case '2' :
case '4' :
case '6' :
case '8' : cout << "You entered an EVEN number..." << endl;
break;
case '1' :
case '3' :
case '5' :
case '7' :
case '9' : cout << "You entered an ODD number..." << endl;
break;
default: cout << "ERROR: Bad input character: " << ch << endl;
} // switch
return 0;
} // main
Home | | Schedule | | Assignments | | Lectures | | Resources
CSCI 131: Techniques of Programming
Last Modified: February 10, 2014
Page Expires: February 10, 2015