/********************************************************************************************
4_57.cpp
Jim Millard
for CO211/Fall 1999
Simple program that counts the number of zero, positive and negative inputs it receives, then
echos those totals to the user.
********************************************************************************************/
#include <iostream>
#include <string>
using namespace std;
void DisplayResults(int countPos, int countNeg, int countZed);
void DoWork(int& countPos, int & countNeg, int &countZed);
int main()
{
int countPos = 0, countNeg = 0, countZed = 0; //accumulators
//inform and prompt the user
cout << endl << "This program will take a set of numbers as input and " << endl;
cout << "returns the count of positives, negatives and zeros in the input." << endl;
cout << "The program will return the summation when you enter [Ctrl-D] as input." << endl;
//get our input until we're done
DoWork(countPos, countNeg, countZed);
DisplayResults(countPos, countNeg, countZed);
return 0;
}
void DisplayResults(int countPos, int countNeg, int countZed)
{
//output the results
cout << "\nResults:" << endl;
cout << "\tPositive: " << countPos << " numbers entered." << endl;
cout << "\tNegative: " << countNeg << " numbers entered." << endl;
cout << "\t Zeros: " << countZed << " zeros entered." << endl;
}
void DoWork(int& countPos, int& countNeg, int& countZed)
{
float value; //for input
cout << "Enter a set of numbers: ";
while (cin >> value)
{
if (0 == value)
countZed++;
else if (0 > value)
countNeg++;
else
countPos++;
//DisplayResults(countPos, countNeg, countZed);
cout << "\nEnter a set of numbers: ";
}
}