hello everyone, i'm starting to learn the C language and was looking for some help from someone more experianced, anyway heres my program code and my problem.
this is kinda for a quiz, although i don't have to do the work myself i must know of an alternative to fix this bug other then the one provided
#include <stdio.h>
int main()
{
float a;
a = 0;
while (a <= 100)
{
if (a > 98.6)
{
printf("%6.2f degrees F = %6.2f degrees C\n", 98.6, (98.6 - 32) * 5.0 / 9.0);
}
printf("%6.2f degrees F = %6.2f degrees C\n", a, (a - 32.0) * 5.0 / 9.0);
a = a + 10;
}
return 0;
}
heres what it says "This program works if the ending value is 100, but if you change the ending value to 200 you will find that the program has a bug. It prints the line for 98.6 degrees too many times. We can fix that problem in several different ways. Here is one way:"
#include <stdio.h>
int main()
{
float a, b;
a = 0;
b = -1;
while (a <= 100)
{
if ((a > 98.6) && (b < 98.6))
{
printf("%6.2f degrees F = %6.2f degrees C\n", 98.6, (98.6 - 32.0) * 5.0 / 9.0);
}
printf("%6.2f degrees F = %6.2f degrees C\n", a, (a - 32.0) * 5.0 / 9.0);
b = a;
a = a + 10;
}
return 0;
}
if anyone knows any other ways other then the example provided to fix this bug it would be very very apppreciated.
thanks
Dustin
this is kinda for a quiz, although i don't have to do the work myself i must know of an alternative to fix this bug other then the one provided
#include <stdio.h>
int main()
{
float a;
a = 0;
while (a <= 100)
{
if (a > 98.6)
{
printf("%6.2f degrees F = %6.2f degrees C\n", 98.6, (98.6 - 32) * 5.0 / 9.0);
}
printf("%6.2f degrees F = %6.2f degrees C\n", a, (a - 32.0) * 5.0 / 9.0);
a = a + 10;
}
return 0;
}
heres what it says "This program works if the ending value is 100, but if you change the ending value to 200 you will find that the program has a bug. It prints the line for 98.6 degrees too many times. We can fix that problem in several different ways. Here is one way:"
#include <stdio.h>
int main()
{
float a, b;
a = 0;
b = -1;
while (a <= 100)
{
if ((a > 98.6) && (b < 98.6))
{
printf("%6.2f degrees F = %6.2f degrees C\n", 98.6, (98.6 - 32.0) * 5.0 / 9.0);
}
printf("%6.2f degrees F = %6.2f degrees C\n", a, (a - 32.0) * 5.0 / 9.0);
b = a;
a = a + 10;
}
return 0;
}
if anyone knows any other ways other then the example provided to fix this bug it would be very very apppreciated.
thanks
Dustin