C# Project; Index two arrays in a method
Go to solution
Solved by vorticalbox,
6 hours ago, Rain7 said:static void Main(string[] args) { decimal[] minimumSalary = new decimal[] { 31600M, 31975M, 32350M, 32725M, 33100M, 33500M, 33900M }; int[] yearsOfExperience = new int[6]; for (int i = 0; i < yearsOfExperience.Length; i++) { Console.WriteLine("Enter the years of Experience: "); yearsOfExperience[i] = int.Parse(Console.ReadLine()); } Console.WriteLine("Total salary is: " + CalculateTotalSalaries(minimumSalary, yearsOfExperience)); Console.ReadKey(); } private static decimal CalculateTotalSalaries(decimal[] minimumSalary, int[] yearsOfExperience) { decimal totalSalary = 0; for (int i = 0; i < yearsOfExperience.Length; i++) { for (int j = 0; j < minimumSalary.Length; j++) { if (yearsOfExperience[i] == j) { totalSalary += minimumSalary[j]; Console.WriteLine(minimumSalary[j]); break; } } } return totalSalary; }
You don't need to loop both arrays just the years of experience
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now