Skip to main content

Module interaction

Module interaction 

Source
Expand description

This module handles all user interaction to gather the necessary information to create an employment scenario struct This includes functions for displaying prompts, receiving input, and showing results. The main function in this module is get_user_input which orchestrates the entire process of gathering information from the user and creating an employment scenario struct.

The get_user_input function first prompts the user to create an employment scenario by calling the create_scenario function, which gathers information about the user’s hourly rate and hours worked per week. Then it prompts the user to enter their living expenses by calling the get_expenses function, which gathers information about various expense categories. Finally, it prompts the user to enter their deductions by calling the get_deductions function, which gathers information about both pre-tax and post-tax deductions. After gathering all the necessary information, it confirms the inputs with the user and then converts the inputs into an employment scenario struct using the convert_inputs_to_struct function.

The create_scenario, get_expenses, and get_deductions functions all follow a similar pattern of prompting the user for input, validating the input, and storing it in a HashMap. The confirm_inputs function is used to display the gathered information back to the user for confirmation before proceeding to create the employment scenario struct. The convert_inputs_to_struct function takes the gathered information from the HashMaps and constructs an EmploymentScenario struct with the appropriate fields populated based on the user’s input.

Functions§

convert_inputs_to_struct
This function takes the three HashMaps containing the user input for the employment scenario, expenses, and deductions, and converts them into an EmploymentScenario struct. It parses the string values from the HashMaps into the appropriate types (e.g., f32) and constructs the EmploymentScenario struct with the corresponding fields populated based on the user’s input.
get_user_input
main function to orchestrate user input and create employment scenario struct This function will call the other functions in this module to gather information from the user and create an employment scenario struct based on that information. It will start by getting the payrate and hours worked per week.