View Single Post
  #3   Spotlight this post!  
Unread 31-12-2009, 00:02
Branden Ghena's Avatar
Branden Ghena Branden Ghena is offline
Previously: tawnos23
FRC #0240 (TEMPEST)
Team Role: College Student
 
Join Date: Nov 2005
Rookie Year: 2004
Location: Houghton, Michigan (MTU)
Posts: 303
Branden Ghena has a spectacular aura aboutBranden Ghena has a spectacular aura aboutBranden Ghena has a spectacular aura about
Re: Kind of off topic c programming question.

Well, from what I can see you have a basic logic issue that probably comes from a series of typos.

Here is your code (note problems in red):
Code:
/* Find the largest number *'


if (input_1 >= input_2 && input_1 >= input_3) {
high_value = input_2;

}
else if (input_2 >= input_2 && input_2 >= input_3) {
high_value = input_2;
}

else if (input_3 >= input_1 && input_3 >= input_2) {
high_value = input_3;
}
This is what the code was probably meant to be (note changes in green):
Code:
/* Find the largest number *'


if (input_1 >= input_2 && input_1 >= input_3) {
high_value = input_1;

}
else if (input_2 >= input_1 && input_2 >= input_3) {
high_value = input_2;
}

else if (input_3 >= input_1 && input_3 >= input_2) {
high_value = input_3;
}
Now, its worth noting that there is a more efficient way to find the highest if you think about it logically.
Code:
/* Find the largest number *'

high_value = input_1;

if (input_2 >= high_value) {
     high_value = input_2;
}

if (input_3 >= high_value) {
    high_value = input_3;
}
But that is not really important because your method should work just fine if the mistypes are corrected.
__________________
Branden Ghena - Michigan Tech Student and Team 240 Alumnus
Working Towards: Electrical Engineering and Computer Engineering Double Major

"All we have to decide is what to do with the time that is given to us." - Gandalf