File tree Expand file tree Collapse file tree 2 files changed +5
-5
lines changed
exercise-solutions/cpp-interop/src Expand file tree Collapse file tree 2 files changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -31,10 +31,10 @@ You should get:
31
31
32
32
Because there are 5 rows of data and a header row.
33
33
34
- 2 . Use ` autocxx ` to read ` weather.csv ` and report average temperature in June:
34
+ 2 . Use ` autocxx ` to read ` weather.csv ` and report the average temperature in June, which should be approximately
35
35
36
36
``` console
37
- 1.1999999999999995
37
+ 1.20
38
38
```
39
39
40
40
A full solution is available at ` rust-exercises/exercises-solutions/cpp-interop ` .
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ fn main() {
15
15
let doc = ffi:: my_csv:: open_csv ( & file_name) . within_unique_ptr ( ) ;
16
16
let count = doc. GetRowCount ( ) ;
17
17
18
- let sum_of_june_temperatures: i64 = ( 0 ..count)
18
+ let sum_of_june_temperatures: f64 = ( 0 ..count)
19
19
. filter_map ( |row_index| {
20
20
let date: UniquePtr < CxxString > = doc. get_string_cell ( 0 , row_index) ;
21
21
let date: & str = date. to_str ( ) . ok ( ) ?;
@@ -25,11 +25,11 @@ fn main() {
25
25
. filter_map ( |row_index| {
26
26
let temperature: UniquePtr < CxxString > = doc. get_string_cell ( 1 , row_index) ;
27
27
let temperature: & str = temperature. to_str ( ) . ok ( ) ?;
28
- temperature. parse :: < i64 > ( ) . ok ( )
28
+ temperature. parse :: < f64 > ( ) . ok ( )
29
29
} )
30
30
. sum ( ) ;
31
31
// June has 30 days
32
- println ! ( "{:.3 }" , sum_of_june_temperatures as f64 / 30.0 ) ;
32
+ println ! ( "{:.2 }" , sum_of_june_temperatures / 30.0 ) ;
33
33
}
34
34
35
35
trait GetStringCell {
You can’t perform that action at this time.
0 commit comments