Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 13.58.200.16
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/snbittner/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/snbittner/extra_credit.cpp
//      CS112 Extra Credit Assignment
//      Due: Wed. Dec. 1, 2010
//
//      File Name: extra_credit.cpp
//      Author: Stephanie Bittner
//      Instructor: Dr. Wang
//
//      Compile: g++ extra_credit.cpp
//      Run: ./a.out < ec.txt
//
//      Goal: The program will read a file with an unknown number of intergers, calculate the average of each line along 
//		with the average of the entire file, then output the results.


#include <iostream>
#include <iomanip>

using namespace std;

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

	float avg;
	int number;
	int sum = 0;
	int counter = 0;

	cin >> number;
	while(cin)
	{
		while(number != -1 )
		{ 
			counter ++;
			sum += number;
		
			cin >> number;
		}

		avg = 1.0 * sum / counter;	
		cout << "The average of each line is: " << avg << endl;

			sum = 0;
			counter = 0;
		
		cin >> number;
	}
		sum += number;
		counter ++;
		cout << "The average of all the lines is:" << 1.0 * sum / 
				counter << endl;

	return 0;
}

Stv3n404 - 2023