Thread: Comparing values

  1. #1
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200

    Comparing values

    I'm trying to write a program that will compare 5 integer values and put them in smallest to biggest order. So far I can only find the smallest and biggest integer. I'm stucking with the other 3 remain in the middle. Here is my code look like:

    Code:
    const int ArraySize = 5;
    
    int getSmallvalue(int card[], int size)
    {
    	int order;
    	int small = 1;
    
    	for(order = 0; order < size; order++)
    	{
    		if(card[small] >= card[order])
    				small = order;
    	}
    
    	return small;
    }
    
    int getBigvalue(int card[], int size)
    {
    	int order;
    	int big = 13;
    	for(order=0; order<size; order++)
    	{
    		if(card[big] <= card[order])
    			big = order;
    	}
    	return big;
    }
    
    int main()
    {
    start:
    	cout<<"Enter 5 cards: "<<endl;
    
    	for(int j=0; j<ArraySize; j++)
    		cin>>CardInput[j];
    
    	for(j=0; j<ArraySize; j++)
    	{
    		if((CardInput[j] < 1) || (CardInput[j] > 52))
    		{
    			cout<<"The card cannot be smaller than 1 or bigger than 52"<<endl;
    			goto start;
    		}
    	}
    
    
    	for(j=0; j<ArraySize; j++)
    	{
    		if((CardInput[j] > 0) && (CardInput[j] <= 13)){
    			Diamond += 1;
    		}
    
    		if((CardInput[j] >= 14) && (CardInput[j] <= 26)){
    			Heart += 1;
    			CardInput[j] -= 13;
    		}
    
    		if((CardInput[j] >= 27) && (CardInput[j] <= 39)){
    			Spade += 1;
    			CardInput[j] -= 26;
    		}
    
    		if((CardInput[j] >= 40) && (CardInput[j] <= 52)){
    			Club += 1;
    			CardInput[j] -= 39;
    		}
    	}
    cout<<"\nSmallest card is: "<<CardInput[getSmallvalue(CardInput, ArraySize)]<<endl;
    cout<<"\nBiggest card is: "<<CardInput[getBigvalue(CardInput, ArraySize)]
    
    }
    The biggest number is 13 and smallest is 1. The number above 13 will be subtract by 13, 26..., so that the value always stays between 1 and 13

    Please help me, and I really don't want to bunch of "if" and "else" statements. They are pain and so confuse in this matter. Thanks
    Last edited by hdragon; 10-06-2005 at 01:26 PM.
    Hello, testing testing. Everthing is running perfectly...for now

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    I'm trying to write a program that will compare 5 integer values and put them in smallest to biggest order.
    1) cin user entries into an array of integers

    2) sort the array in ascending order (bubblesort algorithm is easy.. could also use the sort( ) function from the <algorithm> library.. a google or board search will get you code for basically any sorting algorithm you want)

    3) once the array is sorted, you know the smallest number will be at array[0] and the largest number will be located at array[4]
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Meganan
    Join Date
    Oct 2005
    Posts
    13
    take a look at priority queues they give this exact function.
    Intelligence is Knowledge, but Wisdom is Depth.
    Stupidity is overwhelming.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Storing values from Edit Box into an array
    By E_I_S in forum C++ Programming
    Replies: 10
    Last Post: 06-05-2008, 06:24 AM
  2. putting values into an array
    By zdream8 in forum C Programming
    Replies: 15
    Last Post: 05-21-2008, 11:18 PM
  3. Replies: 1
    Last Post: 12-30-2007, 10:08 AM
  4. Sending values to a control
    By Zyk0tiK in forum C Programming
    Replies: 6
    Last Post: 12-02-2005, 06:29 PM
  5. unsigned char vs signed char and range of values
    By Silvercord in forum C++ Programming
    Replies: 5
    Last Post: 01-22-2003, 01:30 PM