C++ does care if a parameter type and the value passed to it are the same type as it's a strongly typed language. However what's going on here is your integer is being implicitly cast to a float which makes it legal. Check out this table of implicit numeric conversions by Microsoft
Edit:
So there's a couple of things wrong with your code. Firstly your valFunc is essentially doing nothing to your mainVal variable, notice how the value is still 9 after you pass it to the function and not assigned the value of 50? That's because it's passed-by-value, which essentially takes a copy of your variable and any modification to it in the function scope does not persist. The remedy to this issue is to pass-by-reference which can be done by simply appending the & operator onto your type as so:
void valFunc(float& val)
{
val = 50; // Now your mainVal is 50 :)
}
Okay so for your second question:
When I change int mainVal = 9 to float mainVal = 9.0, the output is still 9 and not 9.0. Why doesn't it output as 9.0?
This is nothing to do with your variable not being a floating point value, but more the way the console is printing your value. To get the console to print your value as a floating point you need to include the iomanip header to your project and declare fixed before outputting the value.
Example:
#include <iostream>
#include <iomanip>
using namespace std;
void valFunc(float& val) // Assigning the value will now persist
{
val = 50;
}
int main()
{
float mainVal = 9;
valFunc(mainVal);
cout << "mainVal: " << fixed << mainVal << endl;
return 0;
}
This will print the value of 50.000000 to the console (remember this is 50 and not 9 because I added the reference operator to your valFunc parameter and the value now persists as it was passed-by-reference).
There's one more final touch you can add to make your console output a bit nicer - you can declare setprecision after fixed to tell the console how many decimal places to print.
Example:
// Displays mainVal: 50.00
cout << "mainVal: " << fixed << setprecision(2) << mainVal << endl;