Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. // File program2.cpp
  2. // Author: Joseph Ediger
  3. // Student ID: Y493G938
  4. // Assignment Number: 2
  5. // Purpose: The program will allow you to continually enter numbers until you hit zero. It will then display the largest number in the sequence.
  6. // Last Changed: September 2, 2014
  7.  
  8. #include <iostream>
  9. using namespace std;
  10.  
  11. int main(void)
  12. {
  13.     double a, b; // User Entered
  14.     a = 0;
  15.     b = 1;
  16.  
  17.    
  18.     cout.setf(ios::fixed);
  19.     cout.setf(ios::showpoint);
  20.     cout.precision(3); // Sets three decimal places
  21.  
  22.     cout << "Entering 0 will terminate the sequence of input values." << endl;
  23.     cout << "Enter a number: ";
  24.     cin >> a;
  25.  
  26.     if (a < 0)
  27.         {
  28.             cout << "Negative numbers are invalid. Program will terminate." << endl;
  29.  
  30.             return 0;
  31.         }
  32.  
  33.  
  34.  
  35.  
  36.     while (b != 0)
  37.     {
  38.         double c; // Computed
  39.  
  40.         cout << "Enter a number: ";
  41.         cin >> b;
  42.  
  43.         if (b < 0)
  44.         {
  45.             cout << "Negative numbers are invalid. Program will terminate." << endl;
  46.  
  47.             return 0;
  48.         }
  49.  
  50.         c = b;
  51.         if(c > a)
  52.         {
  53.             a = c;
  54.         }
  55.     }
  56.  
  57.     cout << "The largest number you entered was " << a << endl;
  58.  
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement