Alright, in this situation I want to take a program that I wrote and modify it so it can take an integers and if any of the numbers are negative, it returns a negative number, but if all the numbers are positive, it returns their average. This is the program I would like to modify:
Code:/* This program is a test driver for anyPositiveEOF. Written by: Chubbs1900 Date: 12-01-2007 */ #include <iostream> using namespace std; #ifndef TRUE #define TRUE 1 #define FALSE 0 #endif // Prototype Statements bool anyPositiveEOF (void); int main (void) { // Statements cout << "Enter numbers <EOF> to stop:\n"; cout << "anyPositiveEOF is: " << anyPositiveEOF () << endl; return 0; } // main /* ================= anyPositiveEOF ================== Read number series & determine if any are positive. Pre Nothing Post Returns true if any numbers > 0 Returns false if all numbers <= 0 */ bool anyPositiveEOF (void) { bool anyPositive = false; int numIn; while ( !anyPositive && (cin >> numIn) ) anyPositive = (numIn > 0); return anyPositive; } // anyPositiveEOF /* Results: Enter numbers <EOF> to stop: -1 -2 3 anyPositiveEOF is: 1 Enter numbers <EOF> to stop: -1 -2 -3 ^danyPositiveEOF is: 0 */



LinkBack URL
About LinkBacks




