Thread: Program that asks for column of numbers and prints 2 highest ones won't print the sec

  1. #1
    Registered User
    Join Date
    Oct 2014
    Posts
    225

    Program that asks for column of numbers and prints 2 highest ones won't print the sec

    ond one properly. I have tried several things (many of which are commented out) to get this to work, but the second highest one usually doesn't print the second highest one. Can someone figure out what I am missing?
    Code:
    #include <iostream>
    using namespace std;
    int main ( ) {
        int number;
        int highest;
        // int var = 0;
        int secondhighest = 0;
        int input;
        cout << "How many numbers? ";
        cin >> number;
        cin >> input;
        highest = input;
        secondhighest = input;
        for(int track = 1; track < number; track++) {
                cin >> input;
               // secondhighest = input;
              //  if(second == 4) {
                //          var = second;
                  //        }   
                if(highest <= input) {
                           secondhighest = highest;
                        highest = input;
                           }
                           else if(input >= secondhighest) {
                                input = secondhighest;
                               // secondhighest = input;
                           }
                           // else if(secondhighest > input) {
                          
                         //  }
                           }
                           cout << "Highest: " << highest << endl;
                           cout << "Second: " << secondhighest;
                           }
    Any help would be very appreciated.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Why did you open a new topic for this existing problem?

    Jim

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    << endl;
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  4. #4
    Registered User
    Join Date
    Oct 2014
    Posts
    225
    Any help with this? I still need help.

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    I suggest you stick to the original thread.

    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 42
    Last Post: 01-21-2015, 06:22 PM
  2. Replies: 5
    Last Post: 11-12-2014, 04:59 PM
  3. Replies: 7
    Last Post: 10-22-2011, 01:13 PM
  4. Replies: 8
    Last Post: 12-30-2010, 10:08 PM
  5. Program the prints prime numbers
    By cloudstrife910 in forum C++ Programming
    Replies: 8
    Last Post: 09-22-2010, 03:03 PM