Hi im new to this community but i am quite ok in c programming. im using a so it will test if a value is equal/greater/less if not adds/subtracts what it needs till its condition is no longer true.
im using a while loop cause while loops will hold on to the statement till its false this will edit untill its where i want it to be.
This is in fact a peace of HW/Project but what i dont understand is why for exaple if i entered 2000 for ResLD why will the Neon Green while condition be true and add 10 more to R2 if its so clear that.
100 + 1900 < 2000 is not True. Jump to Neon Green
After that Blue while loop does its thing cause
100 + 1910 > 2000 its true till its false.
then this code should of ended right? wrong!!! it goes in to an Endless loop.
this is what make no sence as well while loop dark Red is tested @
100 + 1900 != 2000 whitch is true: so its false. (end Code)
it dosnt end hear. it just loops. again.
now if you ented 2222 for ResLD. then the code will end flawlessly. so code does work right. in this case.
im using Pelles C for Window XP to run/compile code. plz help and thanks in advance.
Code:
#include <stdio.h>
#define R1 100
/*----------------------------------------------------*/
double main(){
double ResLD;
printf("Enter ResLD to find R2 ");
scanf("%lf", &ResLD);
printf("you entered %lf\n", ResLD);
// Test 2000 for ResLD then Test 2222 ResLD
// i dont know why this is.
double R2 = 0;
while((R1 + R2) != ResLD){
while((R1 + R2) < ResLD) {R2 += 1000; printf("%lf\n",R2);}
while((R1 + R2) > ResLD) {R2 -= 100; printf("%lf\n",R2);}
while((R1 + R2) < ResLD) {R2 += 10; printf("%lf\n",R2);}
while((R1 + R2) > ResLD) {R2 -= 1; printf("%lf\n",R2);}
}
printf(" i found your R2 Value for ResLD :-)");
return(0);
}