954,178 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

I wrote something for this and if you want to put in more numbers its really easy (not as easy if you would just use arrays) if you read the code and see what I'm doing.

#include <iostream>

using namespace std;

int main()
{
	int n1, n2, n3, n4, n5, a, b;
	
	cout << "input n1: ";
	cin >> n1;
	cout << "input n2: ";
	cin >> n2;
	cout << "input n3: ";
	cin >> n3;
	cout << "input n4: ";
	cin >> n4;
	cout << "input n5: ";
	cin >> n5;
	
	for( int i = 1; i <= 5; i++ )
	{
		switch(i)
		{
			case 1:
				a = n1;
				break;
			case 2:
				a = n2;
				break;
			case 3:
				a = n3;
				break;
			case 4:
				a = n4;
				break;
			case 5:
				a = n5;
				break;
		}
		for( int c = 1; c <= 5; c++ )
		{
			switch(c)
			{
				case 1:
					b = n1;
					break;
				case 2:
					b = n2;
					break;
				case 3:
					b = n3;
					break;
				case 4:
					b = n4;
					break;
				case 5:
					b = n5;
					break;
			}
			if( b > a )
			{
				int temp = a;
				a = b;
				b = temp;
			}
			
			switch(i)
			{
				case 1:
					n1 = a;
					break;
				case 2:
					n2 = a;
					break;
				case 3:
					n3 = a;
					break;
				case 4:
					n4 = a;
					break;
				case 5:
					n5 = a;
					break;
			}
			
			switch(c)
			{
				case 1:
					n1 = b;
					break;
				case 2:
					n2 = b;
					break;
				case 3:
					n3 = b;
					break;
				case 4:
					n4 = b;
					break;
				case 5:
					n5 = b;
					break;
			}

		}
		
	}
	
	cout << n1 << " " << n2 << " " << n3 << " " << n4 << " " << n5 << endl;
	
	system("PAUSE");
	return 0;
}
sfuo
Practically a Master Poster
655 posts since Jul 2009
Reputation Points: 164
Solved Threads: 99
 

sfuo, thanks very much! I really bad in making switch statement and perhaps you may put comments in this code to make me easier to read and alter it to use in my programming.. you really helpful.. thanx again..

din_hilmi
Newbie Poster
10 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

What have you really learned in the class so far, what concepts?

You haven't learned about functions or you don't want to use functions?

Can you use the standard functions?

Think of all possible ways you can do this before using the minimum of
32 if statements.

firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
 
sfuo, thanks very much! I really bad in making switch statement and perhaps you may put comments in this code to make me easier to read and alter it to use in my programming.. you really helpful.. thanx again..


He just gave you the entire program and now you want comments (very nice program by the way, sfuo. It works well). Why don't you go through the code, figure out how it works, and after you do, comment it yourself?

VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
 

i already can figure out by myself btw.. thanx 4 criticize me vernon.. I know I would never become a good programmer if continue being feed up like this but somehow, I cant really think properly under stress condition and somewhat, I would try to improve it inches by inches.. I take this as a great lesson to me to think outside the box in every problem solution in future..

din_hilmi
Newbie Poster
10 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

sfuo, nice...
I always use array for this kind of problem. So I also wondering on how to do that without array.

din_hlmi
your due date is this friday right?... hahaha I know it...

solowing
Newbie Poster
1 post since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You