From aadecfacde758d30da5e585cb3cd7367eb061115 Mon Sep 17 00:00:00 2001 From: Andrei F Date: Wed, 12 Oct 2022 12:28:30 -0700 Subject: Completed first exercise --- CST116-Ch6-Debugging/CST116-Ch6-Debugging-Florea.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'CST116-Ch6-Debugging/CST116-Ch6-Debugging-Florea.cpp') diff --git a/CST116-Ch6-Debugging/CST116-Ch6-Debugging-Florea.cpp b/CST116-Ch6-Debugging/CST116-Ch6-Debugging-Florea.cpp index e3eb942..344357a 100644 --- a/CST116-Ch6-Debugging/CST116-Ch6-Debugging-Florea.cpp +++ b/CST116-Ch6-Debugging/CST116-Ch6-Debugging-Florea.cpp @@ -12,10 +12,21 @@ * 3) Put watches on both Fahrenheit and Celsius. * 4) When asked for a temperature, enter 212. * 5) Verify that the value you entered is stored correctly. + * + * Using the debug watch variable, fahrenheit has a float value of 212 + * * 6) Step over the conversion calculation. What is the value * in Celsius? Is that the correct value? No. + * + * The value in Celsius is 0 on the watch for the variables + * * 7) Remember your order of precedence. Put parentheses around * Fahrenheit - 32. This needs to be done before the multiplication. + * + * Done, the parentheses are now around the Fahrenheit - 32, however, + * celsius is still equal to 0, which I think is because of the 5 / 9 (integers) that + * result into a 0. + * * 8) Stop debugging and recompile. * * Debugging Exercise 2 @@ -25,6 +36,9 @@ * 3) Verify that the value you entered is stored correctly. * 4) Step over the conversion calculation. What is the value * in Celsius? Is that the correct value? No. + * + * + * * 5) Look at the division. This is integer division. Therefore, * 5 / 9 = 0. This is not the result we are looking for. * 6) Modify the calculation so that it does floating point division. @@ -52,7 +66,7 @@ int main() // Breakpoint 1 // Put a breakpoint on the following line - celcius = 5 / 9 * fahrenheit - 32; + celcius = 5 / 9 * (fahrenheit - 32); cout << fahrenheit << " degrees F = " << celcius << " degrees C" << endl; -- cgit v1.2.3