# help w/function

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 03-03-2002
Betazep
for (t = 0; t < 10; ++t)
{
for (i = 0; i < 10; ++i)

since you take in the value for size, you might as well use it here for 10.
• 03-03-2002
Betazep
Problem now, it keeps looping.

realize that it is going to say something ~100 times with way you have it set up.

pull the "sorry...." outside of the loop like this

Code:

```for (t = 0; t < 10; ++t) {   for (i = 0; i < 10; ++i)   {       if (array[t] + array[i] == 100)       {         cout << "The numbers equal 100.\n";         set = 1;       }     }     if (set==1)       cout << "Sorry, I cannot find 2 numbers whose sum is 100.\n"; }```
• 03-03-2002
Betazep
or even better

Code:

```int set=0; for (t = 0; t < 10; ++t) {   for (i = 0; i < 10; ++i)   {       if (array[t] + array[i] == 100)       {         cout << "The numbers equal 100.\n";         set++;       }     }     if (set==0)       cout << "Sorry, I cannot find 2 numbers whose sum is 100.\n";     else       cout << "Found " << set << " sets of numbers whose sum is 100\n." }```
Once again this doesn't take into account one number equaling 50. Notice how one number equaling 50 will make it appear that 100 was reached using two different numbers.

I will leave you to the rest....
• 03-03-2002
CindyLou
Thanks Betazep
I'm getting closer...you've been a great help. I appreciate it.
• 03-03-2002
Betazep
A final hint on the problem of calculating the value of the same number if it equals 50...

if/then hint: if number 1 is equal to number 2 then it is the same array position... or rather if number 1 is not equal to number 2 then perform desired operation
• 03-03-2002
CindyLou
got it
thanks betazep, i figured that one out. my only issue now is, I only want it to print one message or the other, not both. everything else checks out - got rid of double hits (two hits on same set of #'s) etc. Think I have the last problem figured out, going to try it now (fingers crossed!).
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12