Server IP : 172.16.15.8 / Your IP : 18.117.94.77 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/cchansen/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// File Name: input3.cpp // // Author: Caitlin Hansen // Instructor: Dr. Wang // Class: cs 212 Comp. Prog. 2 // Due Date: Feb 2, 2009 // Compile: g++ input.cpp // Run: ./a.out // // Goal: The program reads a positive number and outputs it, // smallest, greatest, sum, len, and quits when reading 0 or negative. #include <iostream> #include <iomanip> using namespace std; int main() { // 1. declare variable float x; float smallest, greatest, sum = 0, len = 0; // 2. read cout << "Input a pos., or quit for 0 and neg.: "; cin >> x; smallest = x; greatest = x; // 3. process and out while(x > 0) { // process cout << "The number is: " << x; sum+= x; if(smallest > x) smallest = x; else greatest = x; cout << "\n\nInput a positive number or "; cout << "\n\nEnter 0 or a negative number to quit "; len ++; cin >> x; } cout << fixed; cout << setprecision(1); cout << "The sum of the input is: " << sum; cout << endl; cout << "The length is: " << len; cout << endl; cout << "The smallest number is: " << smallest; cout << endl; cout << "The greatest number is: " << greatest; cout << endl; cout << "\n\nDone. Bye-Bye.\n\n"; return 0; }