Server IP : 172.16.15.8 / Your IP : 18.119.159.196 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: Input2.cpp // // Author: Caitlin Hansen // Instructor: Dr. Wang // Class: cs 212 Comp. Prog. 2 // Due Date: Jan 28, 2009 // Compile: g++ input.cpp // Run: ./a.out // // Goal: The program reads a positive number and outputs it, // smallest, sum, len, and quits when reading 0 or negative. #include <iostream> using namespace std; int main() { // 1. declare variable 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 positive number or "; cout << "\n\n0 or a negative number to quit "; cin >> x; } cout << "Sum is: " << sum << " Length is: " << len; cout << endl; cout << "The smallest is: " << smallest; cout << endl; cout << "\n\nDone. Bye-Bye.\n\n"; return 0; }