import React, { useState } from 'react'; import { Calculator, Plus, Minus, X, Divide, Equal } from 'lucide-react'; const MathSolver = () => { const [expression, setExpression] = useState(''); const [result, setResult] = useState(''); const [history, setHistory] = useState([]); const handleSolve = () => { try { if (!expression.trim()) { alert('অনুগ্রহ করে একটি গাণিতিক সমস্যা লিখুন'); return; } // Basic math expression evaluation (safe evaluation) const sanitizedExpression = expression.replace(/[^0-9+\-*/().\s]/g, ''); const calculatedResult = Function('"use strict"; return (' + sanitizedExpression + ')')(); if (isNaN(calculatedResult) || !isFinite(calculatedResult)) { throw new Error('Invalid calculation'); } const roundedResult = Math.round(calculatedResult * 100000000) / 100000000; setResult(roundedResult.toString()); // Add to history setHistory(prev => [...prev, { expression: expression, result: roundedResult }].slice(-5)); } catch (error) { setResult('ত্রুটি! অবৈধ গাণিতিক সমস্যা'); } }; const handleClear = () => { setExpression(''); setResult(''); }; const handleButtonClick = (value) => { if (value === '=') { handleSolve(); } else if (value === 'C') { handleClear(); } else if (value === '⌫') { setExpression(prev => prev.slice(0, -1)); } else { setExpression(prev => prev + value); } }; const buttons = [ ['C', '⌫', '(', ')'], ['7', '8', '9', '/'], ['4', '5', '6', '*'], ['1', '2', '3', '-'], ['0', '.', '+', '='] ]; return (
{/* Header */}

ম্যাথ সল্ভার

{/* Display */}
setExpression(e.target.value)} placeholder="গাণিতিক সমস্যা লিখুন (যেমন: 5+3*2)" className="w-full text-lg text-gray-800 bg-transparent border-none outline-none" />
{result && (
ফলাফল: {result}
)}
{/* Calculator Buttons */}
{buttons.flat().map((btn, index) => ( ))}
{/* Manual Solve Button */}
{/* History */} {history.length > 0 && (

📋 সাম্প্রতিক গণনা

{history.slice().reverse().map((item, index) => (
{item.expression} = {item.result}
))}
)} {/* Instructions */}

📝 ব্যবহারবিধি:

  • • সাধারণ গণনা: 5+3, 10-4, 6*7, 15/3
  • • জটিল গণনা: (5+3)*2, 10+5*3
  • • দশমিক সংখ্যা: 3.14+2.86
  • • বন্ধনী ব্যবহার করুন গণনার ক্রম ঠিক রাখতে
); }; export default MathSolver;