Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

What have I done wrong with this statement ?

  • 26-11-2000 7:01pm
    #1
    Moderators, Education Moderators Posts: 1,863 Mod ✭✭✭✭


    if( number1 > (number2 & number3))
    			largest = number1;
    		
    		if( number2 > (number1 & number3))
    			largest = number2;
    		
    		if( number3 > (number1 & number2))
    			largest = number3;
    


Comments

  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    Try this:
    if ((number1 > number2) && (number1 > number3))
       largest = number1;
    
    if ((number2 > number1) && (number2 > number3))
       largest = number2;
    
    if ((number3 > number1) && (number3 > number2))
       largest = number3;
    
    

    But there's a better way to get the largest number.....work it out wink.gif



    [This message has been edited by Enygma (edited 26-11-2000).]


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    Slaanesh, the problem is in your comparison statements. Even though you might think
    number1 > (number2 & number3)
    sees if 'number1 is greater than number2 and number3', this isn't how it works - you can't translate it literally.
    What that statement actually does it compares number1 to the bitwise AND of number2 and number3. When doing comparisons you have to do a comparison for every variable, as Enygma has shown you. However when you have a list of say, 100 numbers to compare, this method obviously becomes unfeasible and then a for-loop is probably your best bet.


  • Registered Users, Registered Users 2 Posts: 4,487 ✭✭✭Gerry


    Have they not shown you loops yet over in blanch? That was the first thing we learned.
    Unless you are just looking for the max of 2 numbers, your method is going to be longer and annoying. It would go something like:

    void main(void)
    {
    int array[10] = {1,2,3,4,5,6,7,8,9,10};
    int largest=0;
    largest=array[0];
    for(int i = 1;i<sizeOfArray; i++)
    {
    if array>largest;
    largest=array;
    }
    }



Advertisement