Hey everyone. I'm trying to write a function that reads in a double and checks for incorrect inputs, but it won't let me output the value in main. I have a function that will read in a c-string and check for incorrect inputs, and it will let me output the c-string in main. My question is why would the c-string function hold the value and let me output it to the console but the floating point value is lost? I'm guessing you need to return the value to another variable but it's just weird that one would work and the other doesn't and it's stumping me.
well, an array implies a pointer to the first element. when you call cin.get() you modify the data pointed to.
the parameter int num of getInt() means you pass by value, i.e. the value will be copied. You can easily call getInt(5).
pass by value also means that the passed parameter num is local to the function and has no effect to the value passed by the caller.
If you want that the modification of a parameter has effect to the variable passed by the caller then you need to pass by reference: void getInt(int&num) // Note the &
This also implies a pointer. Now it would be an error to call getInt(5) because you need to provide a variable where the value can actually be stored