I'm working my way through the learncpp.com tutorials and it's going well.
Now I'm on structs and i more or less understand them on a basic level.
One thing i can't get my head around is how to pass some struct parameters to a function that calculates a value and returns it. Below is a sketch i made. As you can see it's not right, but i can't work out what is the fundamental mistake i'm making. Any pointers would be truly welcome! :)
So when you want a fuction to return a value, you should choose its type (is "type" the right word?) according to what it will return? So in this case, it must return a double, so it's type is a double?
So i guess you'd never return a double AND a string from the same fuction? (if you do, what "type" could you make it?!)
or create a small struct/class containing your double and string and have your function pass one of these back
I've just realised you are indeed doing this, so it looks like you're on the right track. when do you do pass your object out of your function, you'll have to change line 18 to print out HourlyRate and HoursWorkPerWeek individually.
Line 17 looks a bit weird with the {} (and not () ), are you sure you want to do this? I could be wrong but that looks like array initialisation list notation.
The type of this function is not 'double'. The type of the return value is 'double'. The type of the return value is specified before the name of the function.
The type of this function is: double()(Earnings), which means it is a type of function that takes one value of type Earnings and returns a value of type double.
Really? Especially seeing as the return statement is returning a value? Also curly braces for initialisation is actually a good idea because it is uniform initialisation which tends to make things easier.
Depends what he/she means by "it".
edit: I've been away from C++ too long I think. Maybe it's time for me to stop giving people wrong information and go away :/