Advertisement
NickG

MaxMin - maxmin.cpp

Feb 28th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. //NickG
  2. //Max-Min
  3.  
  4. #include <iostream>
  5. #include "valid.hpp"
  6. #include "clear.hpp"
  7. using namespace std;
  8.  
  9. int main() {
  10. int least, most;
  11. char response;
  12. clear();
  13. do {    
  14.     least=most=0;  //Reset least and most
  15.     for (int counter=0, check=0, input; counter<=check; counter++) {
  16.        if (counter==0) {
  17.           cout << "How many numbers would you like to compare:";
  18.           cin >> check;
  19.           intvalid(&check);
  20.           cin.ignore(255,'\n');
  21.           clear();
  22.           }
  23.        else {
  24.           cout << "Input a number:";
  25.           cin >> input;
  26.           intvalid(&input);
  27.           cin.ignore(255,'\n');
  28.           if (counter==1)
  29.           {least=most=input;}
  30.           else {
  31.              if (input>most)
  32.              {most=input;}
  33.              if (input<least)
  34.              {least=input;}
  35.              }
  36.           clear();
  37.           }
  38.        }
  39.        
  40.    cout << "The lowest number is " << least << " and it is ";
  41.    if (least%2 == 0)
  42.    {cout << "even." <<endl;}
  43.    else
  44.    {cout << "odd." <<endl;}
  45.    cout << "The greateast number is " << most << " and it is ";
  46.    if (most%2 == 0)
  47.    {cout << "even." <<endl;}
  48.    else
  49.    {cout << "odd." <<endl;}
  50.    
  51.    do { //Response Loop
  52.       cout << "Run Again? (y/n)";
  53.       cin >> response;
  54.       } while ((response!='y')&&(response!='Y')&&(response!='n')&&(response!='N')); //Wait for valid input
  55.    clear();
  56.    } while ((response=='y')||(response=='Y'));
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement