I'm working my way through my college programming in C book as a first step to learning Cocoa. Anyway, I'm stuck playing on a Windows computer at work, and I'm still early in the process so I'm mostly writing command line programs in DOS. Anyway, I'm writing a very simple program but for some reason after I compile the code, the executable is kind of screwed up. I'm wondering if the compiler is messing up or what. Anyway, here's the code:
#include < stdio.h >
#include < math.h >
double hypotenuse(double, double);
main(){
double sideA, sideB, sideC;
char cont='Y';
while (cont == 'Y' || cont == 'y'){
printf("\nEnter the two known lengths, separated by a space: "
scanf("%lf%lf", &sideA, &sideB);
sideC = hypotenuse(sideA, sideB);
printf("Side 1 =\t%.4f\n", sideA);
printf("Side 2 =\t%.4f\n", sideB);
printf("Hypotenuse =\t%.4f\n", sideC);
printf("Would you like to enter another value [Y/N]? ");
scanf("%c", &cont);
}
return 0;
}
double hypotenuse(double a, double b){
double c;
c = sqrt(a*a + b*b);
return c;
}
The problem is that the program keeps breaking out of the while loop without executing the last scanf statement. If I place an identical scanf statement right before the last printf statement, it works fine. I'm thinking it must be a compiler and/or dos problem. So am I just blind and not seeing an obvious problem here?
#include < stdio.h >
#include < math.h >
double hypotenuse(double, double);
main(){
double sideA, sideB, sideC;
char cont='Y';
while (cont == 'Y' || cont == 'y'){
printf("\nEnter the two known lengths, separated by a space: "
scanf("%lf%lf", &sideA, &sideB);
sideC = hypotenuse(sideA, sideB);
printf("Side 1 =\t%.4f\n", sideA);
printf("Side 2 =\t%.4f\n", sideB);
printf("Hypotenuse =\t%.4f\n", sideC);
printf("Would you like to enter another value [Y/N]? ");
scanf("%c", &cont);
}
return 0;
}
double hypotenuse(double a, double b){
double c;
c = sqrt(a*a + b*b);
return c;
}
The problem is that the program keeps breaking out of the while loop without executing the last scanf statement. If I place an identical scanf statement right before the last printf statement, it works fine. I'm thinking it must be a compiler and/or dos problem. So am I just blind and not seeing an obvious problem here?