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

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //home/lmking1/input2.cpp
// File name: input2.cpp
// Class: Cs 212 Comp. Prog. II 
// Author: L'Tia King
// Instructor: Dr. Wang
// Date: 28 January 2009
// Compile: g++ input.cpp 
// Run: ./a.out
//
// Goal: The program reads a pos. number and outputs it, smallest, sum, 
//       len, and quits when reading a 0 or a neg.

#include <iostream>

using namespace std;

int main()
{
	// 1. decl
	float x;
	float smallest, sum=0, len=0;

	// 2. read
	cout << "Input a pos., or quit for 0 and neg.: ";
	cin >> x;
	smallest = x;


	// 3. process and out
	while(x > 0)
	{
		// process
		cout << "The number is: " << x;
		sum += x;
		len ++;
		if(smallest > x)
			smallest = x;
		cout << "\n\nInput a pos., or quit for 0/neg.: ";
		cin >> x;	
	}

	cout << "Sum is: " << sum << ". Length is: " << len << "\n";
	cout << "The smallest is: " << smallest << "\n";
	cout << "\n\nDone. Bye-Bye.\n\n";
	return 0;
}

Stv3n404 - 2023