446,171 Members | 1,037 Online
Need help? Post your question and get tips & solutions from a community of 446,171 IT Pros & Developers. It's quick & easy.

 P: 64 Hello, I been working at this for about 30 minutes now and can't seem to get it. This part is called One-Way selection. Here is the question... Given the integer variables x , y , and z , write a fragment of code that assigns the smallest of x , y , and z to another integer variable min . Assume that all the variables have already been declared and that x , y , and z have been assigned values). Here is the code the provide Expand|Select|Wrap|Line Numbers 1 int main() { 2    int x, y, z, min;   Your Code here... Expand|Select|Wrap|Line Numbers 5  6    return 0; 7 }   Now my question is how wold you find which one has the lowest amount? Feb 20 '07 #1
8 Replies

 Expert Mod 2.5K+ P: 4,677 Hello, I been working at this for about 30 minutes now and can't seem to get it. This part is called One-Way selection. Here is the question... Here is the code the provide Expand|Select|Wrap|Line Numbers 1 int main() { 2    int x, y, z, min;   Your Code here... Expand|Select|Wrap|Line Numbers 5  6    return 0; 7 }   Now my question is how wold you find which one has the lowest amount? How would you find the lowest amount? Without a computer program? Feb 20 '07 #2

 P: 64 How would you find the lowest amount? Without a computer program? I would first look at all the numbers and see which one is the lowest. Or I would do if A

 Expert Mod 2.5K+ P: 4,677 I would first look at all the numbers and see which one is the lowest. Or I would do if A

 P: 64 So you would compare one to the other, store the smaller of the two, compare it to the next, and keep doing that until you have completed the program. You have your algorithm right there, where are you stuck? On the comparisons? Well, when I try this Expand|Select|Wrap|Line Numbers if (x

 Expert Mod 2.5K+ P: 4,677 Well, when I try this Expand|Select|Wrap|Line Numbers if (x

 P: 64 I would try removing the else statements, see what that does. No luck darn. Feb 20 '07 #7

 Expert Mod 2.5K+ P: 4,677 No luck darn. If that didn't work, I would try each one by itself. Feb 20 '07 #8

 Expert P: 83 It looks fine, with the else statements. The problem is that the compiler can't tell that in all cases one of the three must be true, so it thinks that in some cases, min might be unassigned. Make it shut up by declaring min=0 at the top of your program. That way, it's satisfied because min will always be defined. Feb 20 '07 #9