Numbers Game
/* Samir M. Nassar
* samir.nassar@steamedpenguin.com
* License: GNU Public License version 3
* Title: Numbers Game
*/
#include
#include
#include
using namespace std;
int main()
{
int numInput;
int largest;
int evenCounter = 0;
int tally = 0;
int numOld = -99;
cout << "Enter an integer when asked. The program will give you" << endl;
cout << "the average of the even numbers as well as the largst" << endl;
cout << "number entered. The program will stop tabulating numbers" << endl;
cout << "when you enter -99.";
cout << endl;
cout << endl;
while (numInput != -99)
{
cout << "Enter an integer: ";
cin >> numInput;
if ( (numInput % 2) == 0) // Weed out even numbers
{
tally += numInput; // Total sum of even integers
evenCounter++; // How many even integers there are
}
if (numInput > numOld)
{
largest = numInput;
}
else
{
largest = numOld;
}
numOld = numInput;
}
cout << endl;
cout << endl;
if (tally != 0) // This prevents crashes if we enter no even integers.
{
cout << "Average of even numbers: " << tally / evenCounter;
cout << endl;
cout << endl;
}
cout << "The largest number entered is: " << largest;
cout << endl;
cout << endl;
return 0;
}

Comments