Question
Choices number 2 and 3 are not working. Can anyone provide a solution? function WPS_Report() data = {}; while true choice = displayMenu(); switch choice
Choices number 2 and 3 are not working. Can anyone provide a solution? function WPS_Report() data = {}; while true choice = displayMenu(); switch choice case 1 data = addDetails(data); case 2 data = calculateSalaryDelay(data); case 3 printReport(data); case 4 break; otherwise fprintf('Invalid option. Please try again. '); end if choice == 4 break; end end end function choice = displayMenu() clc; fprintf('Welcome to Wage Protection System '); fprintf('1. Add Details '); fprintf('2. Salary Delay '); fprintf('3. Print Report '); fprintf('4. Exit '); choice = input('Enter your choice: '); end function data = addDetails(data) employeeId = input('Enter employee ID: '); name = input('Enter name: ', 's'); salary = input('Enter salary amount: '); if salary < 1000 fprintf('Salary amount is less than 1000. Please enter salary greater than 1000. '); return; end paymentDate = input('Enter payment date (DD-MM-YYYY): ', 's'); dateComponents = datevec(paymentDate, 'dd-mm-yyyy'); if any(dateComponents == 0) fprintf('Invalid date format. Please enter the date in the format DD-MM-YYYY. '); return; end data{end+1} = struct('employeeId', employeeId, 'name', name, 'salary', salary, 'paymentDate', paymentDate, 'salaryDelayed', ''); end function data = calculateSalaryDelay(data) currentDate = datetime('today'); for i = 1:length(data) paymentDate = datetime(data{i}.paymentDate, 'InputFormat', 'dd-MM-yyyy'); if currentDate - paymentDate <= 7 data{i}.salaryDelayed = 'False'; else data{i}.salaryDelayed = 'True'; end end end function printReport(data) currentDate = datetime('today', 'Format', 'dd-MM-yyyy'); fileId = fopen('CentralBank_WPS.csv', 'w'); fprintf(fileId, 'Employee Id,Name,Salary Amount,Payment Date,Salary Delayed '); for i = 1:length(data) fprintf(fileId, '%d,%s,%d,%s,%s ', data{i}.employeeId, data{i}.name, data{i}.salary, data{i}.paymentDate, data{i}.salaryDelayed); end fclose(fileId); fprintf('Report generated as "CentralBank_WPS.csv". '); end
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started