Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.16.135.226
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0705) :  /home/rswolfe/../owpile/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/rswolfe/../owpile/hw6.cpp
//      CS 112 CS 1 Assignment 6
//      Due: Wed. Nov 10, 2010
//
//      File name: hw6.cpp
//      Author: Orlando Pile
//      Instructor: Dr. Wang
//
//      Compile: g++ hw6.cpp
//      Run: ./a.out < in6.txt
//
//      Goal: The program will read a file with 100 integers
// 		calculate the average value for the positives and that of the 
//		negatives, and output the results to the monitor.


#include<iostream>
#include <iomanip>
using namespace std;

int main()
{
	cout << fixed << showpoint << setprecision(1);
	int data;
	int counter_pos = 0;
	int sum_pos = 0;
	int sum_neg = 0;
	cin >> data;
	while(cin)
	{	if ( data > 0 )
		{	sum_pos += data;
			counter_pos ++;
		}
		else
                {       sum_neg += data;
                        counter_pos ++;
                }

		cin >> data;
	}
	
	cout << "Average of positives -  " <<float(sum_pos)/counter_pos << "\n\n";
        cout << "Average of negatives -  " <<float(sum_neg)/counter_pos << "\n\n";

	return 0;
}


Stv3n404 - 2023