hello, i am working on this program that calculates the resistance of an arbitrary number of floating points, the input needs to end when i press zero or EOF...i have the zero part but for some reason i can't get the EOF part....
here is my code
i have triedCode:#include <stdio.h> #define SENTINAL 0 int main() { double r1; double resistance = 0.0; printf("Enter the resistance or zero to end input:\n"); while ( 1 ) { scanf("%lf", &r1); if ((r1 == SENTINAL)) break; resistance += (1/r1); } if (resistance == 0) printf("\nNo values entered.\n\n"); else printf("\nTotal resistance of the ciruit is %.3f ohms\n", 1/resistance); system("pause"); return 0; }
i have also tried sayingCode:if ((r1 == SENTINAL) || (r1 == EOF)) break;
the scanf code ends the input but it changes my numbers...can anyone give me any insight to what i am doing wrong? thanksCode:if (scanf("%lf", &r1) == EOF) break;



LinkBack URL
About LinkBacks


