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

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/kebuck/extra_credit.cpp
//	CS112	Computer Programming Extra Credit
//
//	File: extra_credit.cpp
//	Author: Katie Buck
//	Instructor: Dr. Wang
//
//	Compile: g++ extra_credit.cpp
//	Run: ./a.out < ec.txt
//
//	Goal: The goal of the program is to write a program that will read
// 	an unknown number of integers, calculate the average values of 
//	each line, and that for all lines, and output the result to one
//	 decimal place. 

#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 = 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 = sum + number;
		counter ++;
		cout << "The average of all the lines is " << 1.0*sum / 
				counter << endl;		

	return 0;

}

Stv3n404 - 2023