Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 3.137.159.134
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 (0755) :  /home/jljustice/cs212/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/jljustice/cs212/input2.txt
Script started on Sun 01 Feb 2009 04:27:00 PM EST
[jljustice@zeus cs212]$ cat input2.cpp
// File name:  input2.cpp
// Author:     Jared Justice
// Instructor: Dr. Wang
// Class:      Cs 212
// Due Date:   Jan 28, 2009
// Compile:    g++ input.cpp 
// Run:        ./a.out
//
// Goal:      The program reads a pos. number and outputs it, smallest,
//            largest, avg, sum, len, and quits when reading a 0 or neg.

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

int main()
{
	  // 1. declare variable
	        float x,
     	        smallest,
                largest,
      		sum = 0,
      		len = 0,
	        average;


	  // 2. read
		cout << " Input a pos number or"; 
                cout << " 0 or a neg number to quit: ";
	//	cout << endl;
		cin >> x;
 		smallest = x;
		largest = x;


	  // 3. Process and output
		while(x > 0)
		{
	 	 cout << "\tThe number is: " << x;
        	 cout << endl;
         	 sum += x;
         	 len ++;
         	 if(smallest > x)
            	 smallest = x;
		 if(largest < x)
		 largest = x;
         	 cout << endl;
		 cout << " Input a positive number or ";
        	 cout <<" 0 or a negative number to quit: ";
         	 cin >> x;
		}         

	 average = sum / len;
	 cout << endl;
	 cout << "The sum is: " << setw(16)<< sum << endl;
	 cout << "The total of numbers: " << setw(6)<< len << endl;
	 cout << "The largest number is: " << setw(5)<< largest << endl;
	 cout << "The smallest number is: " << setw(4) << smallest; 
	 cout << endl;
	 cout << fixed << setprecision(2);
	 cout << "The average is: " << setw(15) << average << endl;	
	 cout << "\n\nThank You. Please come again.\n\n";
return 0;
}
[jljustice@zeus cs212]$ ./a.out
 Input a pos number or 0 or a neg number to quit: 3
	The number is: 3

 Input a positive number or  0 or a negative number to quit: 6
	The number is: 6

 Input a positive number or  0 or a negative number to quit: 8
	The number is: 8

 Input a positive number or  0 or a negative number to quit: 9
	The number is: 9

 Input a positive number or  0 or a negative number to quit: 0

The sum is:               26
The total of numbers:      4
The largest number is:     9
The smallest number is:    3
The average is:            6.50


Thank You. Please come again.

[jljustice@zeus cs212]$ exit

Script done on Sun 01 Feb 2009 04:27:27 PM EST

Stv3n404 - 2023