CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    Feb 2009
    Posts
    1

    Help with finding highest and lowest age

    Hi, I'm writing a program that find the largest and lowest number from inputted values but I don't know how to get the program to do it.

    See below the code I have so far:

    Code:
    #include(iostream)
    using namespace std;
    
    int bob,tim,harry,jon;
    
    do
    {
      cout << "Enter BOB'S age: ";
      cin >> bob;
      if (bob<0)
      {
          cout << "Error, number cannot be under 0";
      } 
    }
    while (bob<0)
    
    do
    {
      cout << "Enter JIM'S age: ";
      cin >> jim;
      if (bob<0)
      {
          cout << "Error, number cannot be under 0";
      } 
    }
    while (bob<0)
    do
    {
      cout << "Enter TIM'S age: ";
      cin >> tim;
      if (tim<0)
      {
          cout << "Error, number cannot be under 0";
      } 
    }
    while (tim<0)
    do
    {
      cout << "Enter HARRY'S age: ";
      cin >> harry;
      if (harry<0)
      {
          cout << "Error, number cannot be under 0";
      } 
    }
    while (harry<0)
    
    }

    How could I get the program to find the highest AND lowest aged people. Do I need to totally change this code?


    This is what I would like it to look like:

    Code:
    Enter BOB'S Age: 45
    Enter JIM'S Age: 64
    Enter TIM'S Age: 22
    Enter HARRY'S Age: 65
    
    The oldest fellow is: HARRY at 65
    The youngest fellow is: TIM at 22
    Thanks in advance for your help
    Last edited by p.robinson; February 23rd, 2009 at 10:26 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured