You are viewing our Forum Archives. To view or take place in current topics click here.
Need C++ Help (Will +Rep){Solved}
Posted:

Need C++ Help (Will +Rep){Solved}Posted:

Lood
  • Halloween!
Status: Offline
Joined: Apr 18, 201113Year Member
Posts: 1,175
Reputation Power: 911
Status: Offline
Joined: Apr 18, 201113Year Member
Posts: 1,175
Reputation Power: 911
I have been tasked with creating a very small program that simply organizes 3 numbers in order, no matter what the input order is. For example, if I put in 7, 3, and 4, it would need to output 3, 4, and 7.

My friend helped my write this program:

#include <iostream>
using namespace std;

int main()
{
   int input[3];
   int output[3];
   
   cout << "Enter 3 numbers (seperate with a space): ";
   cin >> input[0] >> input[1] >> input[2];
   
   int lowest;
   int lowComplete = 0;
   
   for (int i = 0; i < 3; i++)
   {
      lowest = 80000;
      for (int o = 0; o < 3; o++)
      {
         if (input[o] < lowest && input[o] > lowComplete)
         {
            lowest = input[o];
         };
      };
      lowComplete = lowest;
      cout << lowest << endl;
      output[i] = lowest;
   };
   
   return 0;
};


I added in a system("pause") after "return 0;" and it's not doing anything. I was just wondering why? Also, would this work at all anyways?

Thanks a ton!


Last edited by Lood ; edited 1 time in total
#2. Posted:
ip
  • E3 2017
Status: Offline
Joined: Dec 30, 201212Year Member
Posts: 3,778
Reputation Power: 3016
Status: Offline
Joined: Dec 30, 201212Year Member
Posts: 3,778
Reputation Power: 3016
You would have to delete the return 0 in order for it to use the system("pause") return.
#3. Posted:
ObscureCoder
  • Resident Elite
Status: Offline
Joined: Jun 29, 201311Year Member
Posts: 211
Reputation Power: 13
Status: Offline
Joined: Jun 29, 201311Year Member
Posts: 211
Reputation Power: 13
When you return from a function you effectively end that function's frame, thus any code after the return statement in said function is what we call 'unreachable code'. Good IDEs should tell you if your code is unreachable.

1) Don't put shit after return 0; they are unreachable.
2) Don't use system("pause"); as that's windows specific and is a retarded thing to use. Use: std::cin.get();
#4. Posted:
Lood
  • E3 2016
Status: Offline
Joined: Apr 18, 201113Year Member
Posts: 1,175
Reputation Power: 911
Status: Offline
Joined: Apr 18, 201113Year Member
Posts: 1,175
Reputation Power: 911
ObscureCoder wrote When you return from a function you effectively end that function's frame, thus any code after the return statement in said function is what we call 'unreachable code'. Good IDEs should tell you if your code is unreachable.

1) Don't put shit after return 0; they are unreachable.
2) Don't use system("pause"); as that's windows specific and is a retarded thing to use. Use: std::cin.get();
Thanks guys! I've only been to two classes so far, taking C++ in college. Not exactly very far through so I am happy someone else could help me!
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.