
Originally Posted by
csmith03
Would I be able to get rid of the flag statement and put
Code:
(while center != (root))
, that way it stops iterating when it finds the root? The iterCount is more for the print statement
Code:
printf("Iteration Count = %d, Root = %d", iterCount, center);
go back and put that added bit I just put in your loop in your code then run that to see what is going on inside of your loop.
as far as that piece of code you just gave me.
Code:
(while center != (root))
how is it going to know what 'root' is? do you have that assigned or declared even as a variable?
where the while ( center != root) would look at it like this
Code:
int center = 100;
int root = 30;
where ( value inside of center != value inside of root)
// it sees it like this;
while ( 100 != 30 )
if you do not increment the root var it will never become equal to center to kick you out of your loop. my math sucks, but what I see in how this needs to be done using this as a guild;
The loop should iterate the print statement "iteration count = %d root = %d" until a point where the root is found.
Code:
while ( flag == 0 )
{
do the math until you find the absolute root value;
root = whatever math needs to be done;
printf(" the count of how many times it does the math on the numbers,
and the results of each completed equation each time it tries to figure it out\n", count, root) ;
count++:
if( root )
flag = 1;
// that stops the loop
}
that is the basic logic behind it. but you have to know when that root value is actually found or not. then use that for the root value, tricky isn't it? 
Mod:
Code:
#include <stdio.h>
int main (void)
{
int b = 0, count = 0, flag = 0;
while ( flag == 0 )
{
b = b + 1;
printf("count = %d root = %d\n", count, b);
count++;
if ( b == 4)
flag = 1;
}
return 0;
}
results
Code:
userx@void:~/bin
$ gcc mathloop.c
userx@void:~/bin
$ ./a.out
count = 0 root = 1
count = 1 root = 2
count = 2 root = 3
count = 3 root = 4
userx@void:~/bin
but I bet you a small duck that @whiteflags can pinnacle on that logic.