CaptainForge
CaptainForge

Reputation: 1385

Swift: Error when multiplying four Double variables

I keep getting an error on the return statement in the "AnalyzeInput" class, "cannot invoke '*' with an argument list of type '($T18, Double)'", which makes no sense because all four of the variables are defined to be Double in their method headers. Here are the two classes relevant, with irrelevant code removed:

class AnalyzeInput {

     // Constructor, initialize InputInfo, add information to it etc etc

    var remainingToAnalyze: String
    var information: InputInfo

    func findOutput() {
        return information.getVolumeAmount() * information.getMeasurement().getMiliplier() * information.getConcentration() * information.getCompoundMolarMass()
    }
}

class InputInfo {
    var volumeAmount: Double = 0
    var measurementType: Measurement = Measurement(short: "null", singular: "null", plural: "null", multiplier: 0)
    var concentration: Double = 0
    var compoundMolarMass: Double = 0

    init () {
    }

    func setVolumeAmount(volumeAmount: Double) {
        self.volumeAmount = volumeAmount
    }

    func setMeasurementType(measurement: Measurement) {
        self.measurementType = measurement
    }

    func setConcentration(concentration: Double) {
        self.concentration = concentration
    }

    func setCompound(compoundMolarMass: Double) {
        self.compoundMolarMass = compoundMolarMass
    }

    func getVolumeAmount() -> Double {
        return volumeAmount
    }

    func getMeasurement() -> Measurement {
        return measurementType
    }

    func getConcentration() -> Double {
        return concentration
    }

    func getCompoundMolarMass() -> Double {
        return compoundMolarMass
    }
}

How can I fix the error?

Upvotes: 1

Views: 142

Answers (1)

Ideasthete
Ideasthete

Reputation: 1541

findOutput does not have a return type of Double. If you want to return a double from it, you need to declare the return type correctly. Also, you don't need all of those getter/setter methods in the second class - you can just use the dot operator to access properties. Finally, 'multiplier' is misspelled in your return call. So:

func findOutput() -> Double {
    return information.volumeAmount * information.measurement.multiplier * information.concentration * information.compoundMolarMass
}

Upvotes: 2

Related Questions