Friday, March 31, 2023

How to make calculator apps



A calculator is an essential tool for anyone who needs to perform arithmetic calculations quickly and accurately. 



While there are plenty of calculators available for purchase,
 
it can be a fun and rewarding experience to build your own calculator.


 In this article
we will go through the steps involved in building a basic calculator using a programming language.





Please copy below this code and past to your website or apk




<!DOCTYPE html>
<html>
<head>
 <title>Calculator</title>
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <style>
  body {
   font-family: Arial, sans-serif;
   margin: 0;
   padding: 0;
   background-color: #f2f2f2;
  }

  .calculator {
   max-width: 400px;
   margin: 20px auto;
   padding: 20px;
   background-color: #fff;
   box-shadow: 0px 0px 10px #aaa;
   border-radius: 5px;
   text-align: center;
  }

  input[type="button"] {
   width: 50px;
   height: 50px;
   font-size: 20px;
   margin: 5px;
   border: none;
   background-color: #f2f2f2;
   box-shadow: 0px 0px 3px #aaa;
   border-radius: 5px;
   cursor: pointer;
  }

  input[type="text"] {
   width: 100%;
   height: 50px;
   font-size: 20px;
   text-align: right;
   margin-bottom: 10px;
   border: none;
   background-color: #f2f2f2;
   box-shadow: 0px 0px 3px #aaa;
   border-radius: 5px;
   padding-right: 10px;
   overflow: hidden;
   text-overflow: ellipsis;
  }
 </style>
</head>
<body>
 <div class="calculator">
  <input type="text" id="display" disabled>
  <input type="button" value="C" onclick="clearDisplay()">
  <input type="button" value="/" onclick="updateDisplay('/')">
  <input type="button" value="*" onclick="updateDisplay('*')">
  <input type="button" value="7" onclick="updateDisplay('7')">
  <input type="button" value="8" onclick="updateDisplay('8')">
  <input type="button" value="9" onclick="updateDisplay('9')">
  <input type="button" value="-" onclick="updateDisplay('-')">
  <input type="button" value="4" onclick="updateDisplay('4')">
  <input type="button" value="5" onclick="updateDisplay('5')">
  <input type="button" value="6" onclick="updateDisplay('6')">
  <input type="button" value="+" onclick="updateDisplay('+')">
  <input type="button" value="1" onclick="updateDisplay('1')">
  <input type="button" value="2" onclick="updateDisplay('2')">
  <input type="button" value="3" onclick="updateDisplay('3')">
  <input type="button" value="=" onclick="calculate()">
 </div>

 <script>
  let input = '';
  let display = document.getElementById('display');

  function updateDisplay(value) {
   input += value;
   display.value = input;
  }

  function calculate() {
   try {
    input = eval(input);
    display.value = input;
   } catch (error) {
    alert('Invalid input');
   }
  }

  function clearDisplay() {
   input = '';
   display.value = '';
  }
 </script>
</body>
</html>

No comments:

Post a Comment

10 Online Jobs for College Students to Earn Money

Title: 10 Online Jobs for College/University Students to Earn Money In today's digital age, earning money online has become easier tha...