Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // File program2.cpp
- // Author: Joseph Ediger
- // Student ID: Y493G938
- // Assignment Number: 2
- // Purpose: The program will allow you to continually enter numbers until you hit zero. It will then display the largest number in the sequence.
- // Last Changed: September 2, 2014
- #include <iostream>
- using namespace std;
- int main(void)
- {
- double a, b; // User Entered
- a = 0;
- b = 1;
- cout.setf(ios::fixed);
- cout.setf(ios::showpoint);
- cout.precision(3); // Sets three decimal places
- cout << "Entering 0 will terminate the sequence of input values." << endl;
- cout << "Enter a number: ";
- cin >> a;
- if (a < 0)
- {
- cout << "Negative numbers are invalid. Program will terminate." << endl;
- return 0;
- }
- while (b != 0)
- {
- double c; // Computed
- cout << "Enter a number: ";
- cin >> b;
- if (b < 0)
- {
- cout << "Negative numbers are invalid. Program will terminate." << endl;
- return 0;
- }
- c = b;
- if(c > a)
- {
- a = c;
- }
- }
- cout << "The largest number you entered was " << a << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement