#How should this code be fixed?

1 messages · Page 1 of 1 (latest)

ancient furnace
#

import gleam/io

pub type Patient {
Patient(name: String, systolic: Int, diastolic: Int)
}
pub fn collect_data(name: String, systolic: Int, diastolic: Int) -> Patient {
{ Patient(name, systolic, diastolic) }
}
pub fn calculate_blood_pressure(patient: Patient) -> Float {
{ Flaot.from_int(patient.systolic) + Float.from_int(patient.diastolic) } / 2.0
}
fn save_data(patient: Patient, blood_pressure: Float) {
// Simulate saving the data
IO.println(
"Saved blood pressure for "
<> patient.name
<> ": "
<> Float.to_string(blood_pressure),
)
}
pub fn process_patient_data(name: String, systolic: Int, diastolic: Int) {
let patient = collect_data(name, systolic, diastolic)
let blood_pressure = calculate_blood_pressure(patient)
save_data(patient, blood_pressure)
}

pub fn main() {
process_patient_data("John Doe", 120, 80)
}

vernal meadow
#

You probably want to float.to_string rather than Float.to_string as Float is a type, not a module

#

And you'll need to import it with import gleam/float

#

Same for IO too

ancient furnace
#

is this line ok: I'm having an error here.
{ Flaot.from_int(patient.systolic) + Float.from_int(patient.diastolic) } / 2.0
│ ^^^^^ Did you mean io?

vernal meadow
#

Yup yup that's as I said above

#

Float is a type, not a module

#

You want to change it to float.parse and import gleam/float

#

I think you may have been looking at docs for Elixir, not Gleam