/* ************************************************************************** * Program name : 007_odd_and_even_numbers.cpp (Version 1.00) * * Author : Duck Wong * * Language : C / C++ * * Compiler : Boodshed Dec-C++ compiler Ver 3.95 * * Computer : PII350 * * O/S : Windows 98 * ************************************************************************** * Version 1.00 : 2000/06/04 - first version * ************************************************************************** * Description : (a) input no. of values in the list * * (b) input the values * * (c) find Max, Min, no. of odd number & even number * * (d) output results * ************************************************************************** */ #include #include int main() { // part 1 : declaration int Max, Min, Odd, Even, Counter, Number, Values; float Average; // part 2 : input & calculation do { cout << "How many positive numbers are there in your list ? "; cin >> Number; } while (Number < 1); Counter = 1; Max = 0; Min = 0; Odd = 0; Even = 0; cout << "\n"; while (Counter <= Number) { do { cout << "Please input the " << Counter << " number : "; cin >> Values; } while (Values < 1); if (Values > Max) Max = Values; if (Counter==1) Min = Values; // note (1) else if (Values < Min) Min = Values; ((Values % 2)==0)? Even = Even + 1 : Odd = Odd + 1; // note (2) Counter = Counter + 1; } // part 3 : output result cout << "\n\aThere are " << Number << " numbers in the list.\n\n" << "Smallest is " << Min << "\n" << "Largest is " << Max << "\n" << "No.s of odd numbers is " << Odd << "\n" << "No.s of even numbers is " << Even << "\n" << endl;; system("PAUSE"); return 0; } /* NOTES (1) if (Counter==1) Min = Values; else if (Values < Min) Min = Values; = statements in Pascal as : IF (Counter=1) THEN Min := Values ELSE IF (Values < Min) THEN Min := Values; (2) ((Values % 2)==0)? Even = Even + 1 : Odd = Odd + 1; is a conditional expression, which equals to the following linea : if ((Values % 2)==0) Even = Even + 1; else Odd = Odd + 1; */