-2

HOW TO MAKE A CALCULATOR| 100% WORKING TRICK 2021

đã đăng vào 18, Tháng 11, 2021, 0:00

Today, I will tell you how to make a basic calculator in c++. Well, you need to know about "WHAT IS A BASIC CALCULATOR". A basic calc (A short form of calculator) is for calculating +, -, *, /. So, copy or remember this code because it's really easy and you don't need any more library. See the code below 👇 in the rectangle box. I've test it on my computer, the worst computer ever :) and success.

The code may 10% not work on other program, so I strongly recommended you install Code::Block. It's completely free and suitable for week computer.

Please feel free to command below if the code does not work. Like this: Visual Studio C++ - Not work

🎞 Subcribe to my youtube at: 👉 https://www.youtube.com/channel/UCvpqlnV29UZks3FsiZGs75w. No video yet, sorry :)

#include <bits/stdc++.h>
using namespace std;

int main()
{
    long double a,b; // Change long double into float or int or double, if you need the limit of the number.
    cout << "Type two number here" << endl; // Change the text in the quote if you want
    cin >> a >> b;
    cout << "Type the type of calculator (+, -, *, /) expected" << endl; // Change the text in the quote if you want
    char type; // You can change "type" into another name (Please follow the variable rules)
    cin >> type;
    switch (type)
    {
    case '+': cout << a + b; break;
    case '-': cout << a - b; break;
    case '*': cout << a * b; break;
    case '/': cout << a / b; break;
    default: cout << "EXPECTED (+, -, *, /)" << endl;
    }
    return 0;
}

Bình luận

Hãy đọc nội quy trước khi bình luận.



  • 0
    star_6a0sonha  đã bình luận lúc 17, Tháng 11, 2021, 14:10

    Rất xin lỗi VNOJ vì đã đăng spoiler mã nguồn, nhưng trong bài đăng mình sợ nó có hơi nhiều chữ nên bỏ sang đây


  • 0
    star_6a0sonha  đã bình luận lúc 17, Tháng 11, 2021, 14:09 sửa 2

    Fixed: Deleted // definition

    #include <bits/stdc++.h>
    using namespace std;
    
    int main()
    {
    long double a,b;
    cout << "Type two number here" << endl;
    cin >> a >> b;
    cout << "Type the type of calculator (+, -, *, /) expected" << endl;
    char type;
    cin >> type;
    switch (type)
    {
    case '+': cout << a + b; break;
    case '-': cout << a - b; break;
    case '*': cout << a * b; break;
    case '/': cout << a / b; break;
    default: cout << "EXPECTED (+, -, *, /)" << endl;
    }
    return 0;
    }