Calculate Weighted Average: Formula, Examples & Calculator
:root {
–primary-color: #004a99;
–secondary-color: #f8f9fa;
–success-color: #28a745;
–text-color: #333;
–border-color: #ddd;
–shadow-color: rgba(0, 0, 0, 0.1);
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
color: var(–text-color);
background-color: var(–secondary-color);
margin: 0;
padding: 20px;
}
.container {
max-width: 980px;
margin: 0 auto;
background-color: #fff;
padding: 30px;
border-radius: 8px;
box-shadow: 0 4px 15px var(–shadow-color);
}
h1, h2, h3 {
color: var(–primary-color);
margin-bottom: 15px;
}
h1 {
text-align: center;
font-size: 2.2em;
margin-bottom: 25px;
}
h2 {
font-size: 1.8em;
border-bottom: 2px solid var(–primary-color);
padding-bottom: 5px;
margin-top: 30px;
}
h3 {
font-size: 1.3em;
margin-top: 20px;
}
.calculator-wrapper {
background-color: var(–secondary-color);
padding: 25px;
border-radius: 8px;
margin-bottom: 30px;
box-shadow: inset 0 2px 5px rgba(0,0,0,0.05);
}
.loan-calc-container {
display: flex;
flex-direction: column;
gap: 15px;
}
.input-group {
display: flex;
flex-direction: column;
gap: 5px;
}
.input-group label {
font-weight: bold;
color: var(–primary-color);
}
.input-group input[type="number"],
.input-group input[type="text"],
.input-group select {
padding: 10px 12px;
border: 1px solid var(–border-color);
border-radius: 5px;
font-size: 1em;
transition: border-color 0.3s ease;
}
.input-group input[type="number"]:focus,
.input-group input[type="text"]:focus,
.input-group select:focus {
border-color: var(–primary-color);
outline: none;
}
.input-group .helper-text {
font-size: 0.85em;
color: #666;
}
.error-message {
color: #dc3545;
font-size: 0.85em;
margin-top: 5px;
display: none; /* Hidden by default */
}
.button-group {
display: flex;
gap: 15px;
margin-top: 20px;
flex-wrap: wrap; /* Allow wrapping on smaller screens */
}
.btn {
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 1em;
font-weight: bold;
transition: background-color 0.3s ease, transform 0.2s ease;
white-space: nowrap; /* Prevent button text from breaking */
}
.btn-primary {
background-color: var(–primary-color);
color: white;
}
.btn-primary:hover {
background-color: #003366;
transform: translateY(-2px);
}
.btn-secondary {
background-color: #6c757d;
color: white;
}
.btn-secondary:hover {
background-color: #5a6268;
transform: translateY(-2px);
}
.btn-success {
background-color: var(–success-color);
color: white;
}
.btn-success:hover {
background-color: #218838;
transform: translateY(-2px);
}
.results-container {
background-color: var(–primary-color);
color: white;
padding: 20px;
border-radius: 8px;
margin-top: 25px;
box-shadow: 0 4px 10px rgba(0, 74, 153, 0.3);
text-align: center;
}
.results-container h3 {
color: white;
margin-top: 0;
font-size: 1.5em;
}
.main-result {
font-size: 2.5em;
font-weight: bold;
margin: 10px 0;
padding: 10px;
background-color: rgba(255, 255, 255, 0.2);
border-radius: 5px;
display: inline-block; /* To fit content */
}
.intermediate-results {
margin-top: 15px;
font-size: 1.1em;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 15px;
text-align: left;
}
.intermediate-results div {
padding: 10px;
background-color: rgba(255, 255, 255, 0.1);
border-radius: 5px;
}
.intermediate-results span {
font-weight: bold;
display: block;
font-size: 1.3em;
}
.formula-explanation {
font-size: 0.9em;
color: rgba(255, 255, 255, 0.8);
margin-top: 15px;
font-style: italic;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
box-shadow: 0 2px 5px var(–shadow-color);
}
thead {
background-color: var(–primary-color);
color: white;
}
th, td {
padding: 12px 15px;
text-align: left;
border: 1px solid var(–border-color);
}
tbody tr:nth-child(even) {
background-color: #f2f2f2;
}
caption {
font-size: 1.1em;
font-weight: bold;
color: var(–primary-color);
margin-bottom: 10px;
text-align: left;
}
.chart-container {
text-align: center;
margin-top: 30px;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 5px var(–shadow-color);
}
canvas {
max-width: 100%;
height: auto;
display: block; /* Remove extra space below canvas */
margin: 0 auto; /* Center canvas */
}
.article-section {
margin-top: 40px;
padding-top: 20px;
border-top: 1px solid #eee;
}
.article-section:first-of-type {
border-top: none;
margin-top: 0;
padding-top: 0;
}
.faq-item {
margin-bottom: 15px;
}
.faq-item h3 {
margin-bottom: 5px;
color: var(–primary-color);
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
}
.faq-item h3:after {
content: '+';
font-size: 1.2em;
transition: transform 0.3s ease;
}
.faq-item.open h3:after {
transform: rotate(45deg);
}
.faq-item .answer {
display: none;
margin-top: 10px;
padding-left: 15px;
border-left: 2px solid var(–primary-color);
font-size: 0.95em;
}
#internalLinksList {
list-style: none;
padding: 0;
}
#internalLinksList li {
margin-bottom: 15px;
padding-bottom: 10px;
border-bottom: 1px solid #eee;
}
#internalLinksList li:last-child {
border-bottom: none;
margin-bottom: 0;
padding-bottom: 0;
}
#internalLinksList a {
font-weight: bold;
color: var(–primary-color);
text-decoration: none;
transition: color 0.3s ease;
}
#internalLinksList a:hover {
color: #003366;
text-decoration: underline;
}
#internalLinksList p {
font-size: 0.9em;
color: #555;
margin-top: 5px;
}
.responsive-table-wrapper {
overflow-x: auto;
}
@media (max-width: 768px) {
.container {
padding: 20px;
}
h1 {
font-size: 1.8em;
}
h2 {
font-size: 1.5em;
}
.btn {
flex-grow: 1; /* Make buttons take available space */
padding: 12px;
}
.button-group {
flex-direction: column;
gap: 10px;
}
.results-container {
padding: 15px;
}
.main-result {
font-size: 2em;
}
.intermediate-results {
grid-template-columns: 1fr;
}
th, td {
padding: 10px 8px;
font-size: 0.9em;
}
}
Weighted Average Calculator
Calculation Results
—
Formula: SUM(Value * Weight) / SUM(Weight)
Weighted Average Distribution
Visual representation of values and their weights.
Data Input Summary
| Value |
Weight |
(Value * Weight) |
| — |
— |
— |
| — |
— |
— |
| — |
— |
— |
What is Weighted Average?
A weighted average is a type of average that takes into account the varying importance or "weight" of each data point in a set. Unlike a simple average (arithmetic mean), where every value contributes equally, a weighted average assigns different levels of significance to different values. This means some numbers have a greater influence on the final average than others, based on their assigned weights.
Who Should Use It?
Anyone working with data where not all points are created equal should consider using a weighted average. This includes:
- Students and Educators: Calculating final grades where different assignments (homework, exams, projects) have different point values or percentages.
- Investors: Determining the average cost basis of assets purchased at different prices and quantities.
- Business Analysts: Calculating average performance metrics across different product lines or regions, each contributing differently to overall success.
- Statisticians and Researchers: Analyzing survey data where different demographic groups may have different representation sizes or reliability.
- Inventory Management: Calculating the average cost of inventory when goods are purchased at various prices over time.
Common Misconceptions
A frequent misunderstanding is that a weighted average is overly complex or only for advanced mathematics. In reality, it's a practical tool for representing a more accurate central tendency when data has inherent differences in importance. Another misconception is that weights must add up to 1 (or 100%). While this is a common practice for simplification, it's not a strict requirement; the formula works regardless, as the weights are used proportionally.
The weighted average calculator above simplifies this process, allowing you to quickly grasp its application without manual computation.
Weighted Average Formula and Mathematical Explanation
The core idea behind the weighted average is to adjust the influence of each value by its corresponding weight. The formula is derived by summing the product of each value and its weight, and then dividing by the sum of all the weights.
Let's break down the formula:
Weighted Average = Σ(vᵢ * wᵢ) / Σwᵢ
Where:
- vᵢ represents the i-th value in your dataset.
- wᵢ represents the weight assigned to the i-th value.
- Σ (Sigma) is the symbol for summation, meaning "add up".
In simpler terms:
- Multiply each value by its corresponding weight.
- Add up all these products.
- Add up all the weights.
- Divide the sum of the products (from step 2) by the sum of the weights (from step 3).
Variables Table
Weighted Average Variables
| Variable |
Meaning |
Unit |
Typical Range |
| vᵢ |
Individual Data Value |
Depends on context (e.g., score, price, quantity) |
Varies widely |
| wᵢ |
Weight of the Value |
Unitless (or can represent proportion, frequency, importance) |
Non-negative (0 or greater) |
| Σ(vᵢ * wᵢ) |
Sum of each value multiplied by its weight |
Same unit as vᵢ |
Varies widely |
| Σwᵢ |
Sum of all weights |
Unitless |
Sum of non-negative numbers (typically > 0) |
| Weighted Average |
The calculated average value, adjusted for weights |
Same unit as vᵢ |
Typically falls between the minimum and maximum values of vᵢ |
Understanding these variables is key to correctly applying the weighted average formula. Our calculator automates this, but knowing the underlying math empowers accurate data interpretation.
Practical Examples (Real-World Use Cases)
The weighted average is a versatile tool with numerous applications. Here are a couple of practical examples:
Example 1: Calculating a Student's Final Grade
A student is completing a course where the final grade is determined by different components, each with a specific weight:
- Homework: Score of 90, weight of 20% (0.20)
- Midterm Exam: Score of 75, weight of 30% (0.30)
- Final Exam: Score of 85, weight of 50% (0.50)
Calculation:
Sum of (Value * Weight) = (90 * 0.20) + (75 * 0.30) + (85 * 0.50)
= 18 + 22.5 + 42.5 = 83
Sum of Weights = 0.20 + 0.30 + 0.50 = 1.00
Weighted Average = 83 / 1.00 = 83
Interpretation: The student's final weighted average grade is 83. Notice how the final exam, with its higher weight, had a greater impact on the final score than the homework.
Example 2: Calculating Average Cost of Inventory
A company purchases inventory at different times and prices:
- Purchase 1: 100 units at $10 per unit (Weight = 100 units)
- Purchase 2: 200 units at $12 per unit (Weight = 200 units)
- Purchase 3: 150 units at $11 per unit (Weight = 150 units)
Calculation:
Sum of (Value * Weight) = (10 * 100) + (12 * 200) + (11 * 150)
= 1000 + 2400 + 1650 = 5050
Sum of Weights = 100 + 200 + 150 = 450 units
Weighted Average = 5050 / 450 = $11.22 (approximately)
Interpretation: The average cost per unit of inventory, considering the quantity of each purchase, is approximately $11.22. This provides a more accurate picture of inventory cost than a simple average of the prices ($10, $12, $11).
Our weighted average calculator can help you run these scenarios quickly.
How to Use This Weighted Average Calculator
Our calculator is designed for simplicity and accuracy. Follow these steps to get your weighted average:
- Enter Values: Input your numerical data points into the "Value" fields (Value 1, Value 2, Value 3, etc.).
- Assign Weights: For each value, enter its corresponding "Weight". Weights represent the relative importance or contribution of each value. They must be non-negative numbers. Common practices include using percentages (e.g., 0.20 for 20%) or raw counts/frequencies.
- Calculate: Click the "Calculate" button.
How to Read Results
- Primary Result (Weighted Average): This is the main output, displayed prominently. It represents the average of your values, adjusted for their assigned weights.
- Intermediate Values:
- Sum of (Value * Weight): The total sum after multiplying each value by its weight.
- Sum of Weights: The total sum of all the weights you entered.
- Total Data Points: The number of value-weight pairs you entered.
- Table Summary: The table below the calculator provides a clear breakdown of each input row, including the calculated product of value and weight.
- Chart: The dynamic chart visually illustrates the distribution of your values and their respective weights, offering a quick insight into the data's structure.
Decision-Making Guidance
The weighted average is more informative than a simple average when data points have unequal significance. Use it when you need a representative central value that accurately reflects the contribution of each part. For instance, if calculating a portfolio's average return, weighting each asset by its proportion in the portfolio gives a truer picture of overall performance.
Use the "Copy Results" button to easily share your findings or input them into other documents. The "Reset" button allows you to start fresh with new calculations.
Key Factors That Affect Weighted Average Results
Several factors can significantly influence the outcome of a weighted average calculation. Understanding these is crucial for accurate interpretation:
- Magnitude of Weights: Higher weights increase a value's influence. A small change in a value with a high weight will shift the weighted average more than a large change in a value with a low weight. For example, in calculating a course grade, a final exam (high weight) has a much larger impact than a single homework assignment (low weight).
- Distribution of Weights: If weights are heavily concentrated on a few values, the weighted average will be pulled strongly towards those values. Conversely, if weights are evenly distributed, the weighted average will be closer to a simple average.
- Range of Values: The difference between the highest and lowest values in your dataset matters. The weighted average will always fall within the range of the values being averaged (unless all weights are zero, which is an edge case).
- Outliers: A value that is significantly higher or lower than others can heavily influence the weighted average, especially if it has a substantial weight. Careful consideration of outliers and their validity is important.
- Zero Weights: Values with a weight of zero do not contribute to the weighted average calculation at all. They are effectively excluded from the average.
- Non-Negative Weights: Weights must be non-negative. Negative weights are mathematically possible but lack practical interpretation in most real-world scenarios like grades or costs, and can lead to nonsensical results. Our calculator enforces this.
- Units Consistency: While weights are typically unitless, the values themselves must have consistent units if you expect a meaningful average. Averaging prices with quantities requires multiplying them first to get total cost, then dividing by total quantity.
By carefully considering how these factors interact, you can ensure your weighted average provides a truly representative insight into your data.
Frequently Asked Questions (FAQ)
What's the difference between a simple average and a weighted average?
A simple average (arithmetic mean) gives equal importance to all values. A weighted average assigns different levels of importance (weights) to each value, meaning some values have a greater influence on the final result than others.
Do the weights have to add up to 1?
No, the weights do not necessarily have to add up to 1. While it's common practice (especially when using percentages), the formula works correctly as long as you divide the sum of (value * weight) by the sum of the weights. If weights don't sum to 1, the result is simply scaled accordingly.
Can weights be negative?
Mathematically, yes, but in most practical applications like grades, scores, or costs, weights should be non-negative (zero or positive). Negative weights can lead to results that are difficult to interpret or don't make real-world sense. Our calculator requires non-negative weights.
What if I have more than three values?
The provided calculator is set up for three value-weight pairs for simplicity. To calculate for more, you would manually extend the formula: add more rows to the sum of (value * weight) and sum of weights calculations. For extensive datasets, you'd typically use spreadsheet software or programming scripts.
How do I choose the right weights?
Choosing weights depends entirely on the context. For grades, weights often reflect the allocated percentage of the final grade for each assignment type. For inventory cost, weights are the quantity purchased. For survey data, weights might reflect the proportion of a demographic group in the population. The key is that weights should reflect the relative importance or frequency of each value.
Can the weighted average be outside the range of the individual values?
No, the weighted average will always fall between the minimum and maximum individual values in the dataset (inclusive), provided all weights are non-negative and at least one weight is positive.
What is an example of a situation where a simple average would be misleading?
Consider a company's profit. If one division makes $1M profit with 10 employees, and another makes $50K profit with 100 employees, a simple average profit per employee ($525K) is highly misleading. A weighted average (total profit / total employees) gives the true average profit per employee ($9,545).
Is this calculator suitable for financial portfolios?
Yes, absolutely. You can use it to calculate the weighted average return of a portfolio. Set the 'Values' as the returns of individual assets and the 'Weights' as the proportion (percentage) of the total portfolio value each asset represents.
Related Tools and Internal Resources
var chartInstance = null; // Global variable to hold chart instance
function getInputValue(id) {
var inputElement = document.getElementById(id);
if (!inputElement) return NaN;
var value = parseFloat(inputElement.value);
return isNaN(value) ? NaN : value;
}
function setErrorMessage(id, message) {
var errorElement = document.getElementById('error' + id.charAt(0).toUpperCase() + id.slice(1));
if (errorElement) {
errorElement.innerText = message;
errorElement.style.display = message ? 'block' : 'none';
}
}
function validateInput(id, label, minValue = null, maxValue = null) {
var value = getInputValue(id);
var requiredMessage = label + ' is required.';
var invalidMessage = 'Please enter a valid number for ' + label + '.';
var rangeMessage = label + ' must be between ' + minValue + ' and ' + maxValue + '.';
var negativeMessage = label + ' cannot be negative.';
if (isNaN(value)) {
setErrorMessage(id, requiredMessage);
return false;
}
if (minValue !== null && value maxValue) {
setErrorMessage(id, rangeMessage);
return false;
}
setErrorMessage(id, "); // Clear error
return true;
}
function updateTable(v1, w1, vw1, v2, w2, vw2, v3, w3, vw3) {
var tableBody = document.getElementById('dataTableBody');
if (!tableBody) return;
var rows = tableBody.getElementsByTagName('tr');
if (rows.length < 3) {
// Should not happen if structure is correct, but good for robustness
return;
}
var cells1 = rows[0].getElementsByTagName('td');
var cells2 = rows[1].getElementsByTagName('td');
var cells3 = rows[2].getElementsByTagName('td');
if (cells1.length === 3) {
cells1[0].innerText = isNaN(v1) ? '–' : v1;
cells1[1].innerText = isNaN(w1) ? '–' : w1;
cells1[2].innerText = isNaN(vw1) ? '–' : vw1.toFixed(2);
}
if (cells2.length === 3) {
cells2[0].innerText = isNaN(v2) ? '–' : v2;
cells2[1].innerText = isNaN(w2) ? '–' : w2;
cells2[2].innerText = isNaN(vw2) ? '–' : vw2.toFixed(2);
}
if (cells3.length === 3) {
cells3[0].innerText = isNaN(v3) ? '–' : v3;
cells3[1].innerText = isNaN(w3) ? '–' : w3;
cells3[2].innerText = isNaN(vw3) ? '–' : vw3.toFixed(2);
}
}
function updateChart(values, weights, weightedAvg) {
var ctx = document.getElementById('weightedAvgChart').getContext('2d');
// Destroy previous chart instance if it exists
if (chartInstance) {
chartInstance.destroy();
}
var labels = [];
var dataSeries1 = []; // Values
var dataSeries2 = []; // Weighted Average line
for (var i = 0; i < values.length; i++) {
labels.push('Item ' + (i + 1));
dataSeries1.push(values[i]);
}
// Add weighted average line, repeating it for each data point for visual continuity
for (var i = 0; i = 0
if (!validateInput('value2', 'Value 2')) valid = false;
if (!validateInput('weight2', 'Weight 2', 0)) valid = false;
if (!validateInput('value3', 'Value 3')) valid = false;
if (!validateInput('weight3', 'Weight 3', 0)) valid = false;
if (!valid) {
document.getElementById('resultsContainer').style.display = 'none';
return;
}
var sumValueWeight = (value1 * weight1) + (value2 * weight2) + (value3 * weight3);
var sumWeights = weight1 + weight2 + weight3;
var dataPoints = 3; // Fixed for this calculator structure
var weightedAverage = 0;
var displaySumValueWeight = '–';
var displaySumWeights = '–';
var displayDataPoints = '–';
if (sumWeights > 0) {
weightedAverage = sumValueWeight / sumWeights;
displaySumValueWeight = sumValueWeight.toFixed(2);
displaySumWeights = sumWeights.toFixed(2);
displayDataPoints = dataPoints;
document.getElementById('weightedAverageResult').innerText = weightedAverage.toFixed(2);
document.getElementById('sumValueWeight').innerText = displaySumValueWeight;
document.getElementById('sumWeights').innerText = displaySumWeights;
document.getElementById('dataPointsCount').innerText = displayDataPoints;
document.getElementById('resultsContainer').style.display = 'block';
// Update Table
updateTable(value1, weight1, value1 * weight1, value2, weight2, value2 * weight2, value3, weight3, value3 * weight3);
// Update Chart
var values = [value1, value2, value3];
var weights = [weight1, weight2, weight3]; // Although not directly plotted, good to pass context
updateChart(values, weights, weightedAverage);
} else {
// Handle case where sum of weights is zero (all weights are 0)
document.getElementById('weightedAverageResult').innerText = 'N/A';
document.getElementById('sumValueWeight').innerText = '0.00';
document.getElementById('sumWeights').innerText = '0.00';
document.getElementById('dataPointsCount').innerText = dataPoints;
document.getElementById('resultsContainer').style.display = 'block';
// Update Table
updateTable(value1, weight1, value1 * weight1, value2, weight2, value2 * weight2, value3, weight3, value3 * weight3);
// Update Chart with N/A average
updateChart(values, weights, 0); // Passing 0 as average when sumWeights is 0
}
}
function resetForm() {
document.getElementById('value1').value = ";
document.getElementById('weight1').value = ";
document.getElementById('value2').value = ";
document.getElementById('weight2').value = ";
document.getElementById('value3').value = ";
document.getElementById('weight3').value = ";
// Clear error messages
var errorElements = document.querySelectorAll('.error-message');
for (var i = 0; i < errorElements.length; i++) {
errorElements[i].innerText = '';
errorElements[i].style.display = 'none';
}
// Hide results and reset to defaults
document.getElementById('resultsContainer').style.display = 'none';
document.getElementById('weightedAverageResult').innerText = '–';
document.getElementById('sumValueWeight').innerText = '–';
document.getElementById('sumWeights').innerText = '–';
document.getElementById('dataPointsCount').innerText = '–';
// Reset table to defaults
updateTable('–', '–', '–', '–', '–', '–', '–', '–', '–');
// Reset chart if it exists
if (chartInstance) {
chartInstance.destroy();
chartInstance = null;
var canvas = document.getElementById('weightedAvgChart');
var ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height); // Clear canvas content
}
}
function copyResults() {
var weightedAvg = document.getElementById('weightedAverageResult').innerText;
var sumVW = document.getElementById('sumValueWeight').innerText;
var sumW = document.getElementById('sumWeights').innerText;
var dataPoints = document.getElementById('dataPointsCount').innerText;
var value1 = document.getElementById('value1').value || '–';
var weight1 = document.getElementById('weight1').value || '–';
var value2 = document.getElementById('value2').value || '–';
var weight2 = document.getElementById('weight2').value || '–';
var value3 = document.getElementById('value3').value || '–';
var weight3 = document.getElementById('weight3').value || '–';
var resultText = "Weighted Average Calculation Results:\n\n";
resultText += "Key Assumptions:\n";
resultText += "- Value 1: " + value1 + "\n";
resultText += "- Weight 1: " + weight1 + "\n";
resultText += "- Value 2: " + value2 + "\n";
resultText += "- Weight 2: " + weight2 + "\n";
resultText += "- Value 3: " + value3 + "\n";
resultText += "- Weight 3: " + weight3 + "\n\n";
resultText += "Results:\n";
resultText += "Weighted Average: " + weightedAvg + "\n";
resultText += "Sum of (Value * Weight): " + sumVW + "\n";
resultText += "Sum of Weights: " + sumW + "\n";
resultText += "Total Data Points: " + dataPoints + "\n\n";
resultText += "Formula Used: SUM(Value * Weight) / SUM(Weight)";
navigator.clipboard.writeText(resultText).then(function() {
alert('Results copied to clipboard!');
}).catch(function(err) {
console.error('Failed to copy results: ', err);
prompt('Copy this text manually:', resultText); // Fallback for browsers without clipboard API or in secure contexts
});
}
function toggleFaq(element) {
var faqItem = element.parentElement;
faqItem.classList.toggle('open');
var answer = faqItem.querySelector('.answer');
if (answer) {
answer.style.display = faqItem.classList.contains('open') ? 'block' : 'none';
}
}
// Initial calculation on load if there are default values (optional)
// document.addEventListener('DOMContentLoaded', function() {
// // Optionally pre-fill and calculate if you have default values
// // document.getElementById('value1').value = 85;
// // document.getElementById('weight1').value = 0.3;
// // calculateWeightedAverage();
// });
// Add event listeners for real-time updates if desired, or keep button click
var inputFields = document.querySelectorAll('.loan-calc-container input');
for (var i = 0; i < inputFields.length; i++) {
inputFields[i].addEventListener('input', function() {
// Optionally call calculateWeightedAverage() here for real-time updates
// For this example, we keep it on button click to avoid excessive calculations
});
}