Passing multiple values in fields as mentioned in another field (as number of values) by user
You can ref Examples for Developers Module. The module comes with various sub-modules for developers to start with.

Similar kind of functionality is already provided as an example in "AJAX Example" module in Examples module. i.e. User has been given a dropdown field with predefined numbers to render those many fields. Check screenshot below:


Hope this helps.