Server IP : 172.16.15.8 / Your IP : 18.191.215.30 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/tasantos/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// Due date: Feb 6, 2008 // File Name: hw1a.cpp // Author: Tara Santos // Due Date: Feb. 6, 2008 // Instructor: Dr. John Wang // Compilation: vi hw1.cpp // Execution: g++ hw1.cpp // Goal: Write a program that prompts a message and lets the user// input natural numbers. The program will quit when a // negative number is typed in. The program will output the// following results to the screen: average value (display // to one decimal place) and the largest number typed in. // Don't use arrays for this program. #include<iostream> #include<iomanip> using namespace std; int main() { int num; float total= 0; float size= 0; int largest; float avg; cout << fixed << showpoint << setprecision(1); cout << "Input numbers (-)to quit:\n"; cin >> num; largest = num; while(num > 0) { if(largest < num) largest = num; total= total + num; size ++; cin >> num; } avg = float(total)/size; cout << "The total is: " << total << endl; cout << "The size is: " << size << endl; cout << "The largest is: " << largest << endl; cout << "The average is: " << avg << endl; cout << "\n\n______________\n\nDone.\n "; return 0; }