Search
 
SCRIPT & CODE EXAMPLE
 

CPP

calculator c++

#include <iostream>
#include <string>
#include <unistd.h>

using namespace std;

class Calculator
{
private:
    char i_numOperator;
    float i_a = 00.0f, i_b = 00.0f;
public:
    Calculator(char numOperator, float a, float b)
    {
        i_numOperator = numOperator;
        i_a = a;
        i_b = b;
    }

    float the_calculator()
    {
        switch (i_numOperator)
        {
        case '+':
            return (i_a + i_b);
            break;
        case '-':
            return (i_a - i_b);
            break;
        case '*':
            return (i_a * i_b);
            break;
        case '/':
            return (i_a / i_b);
            break;
        
        default:
            cout << "invalid operator please try again
";
            break;
        }
    }
};

int main() {
    char again = 'y';
    while(again == 'y' || again == 'Y')
    {
        int a = 00.0f, b = 00.0f;
        char op;

        cout << "first num
";
        cin >> a;
        cout << "operator
";
        cin >> op;
        cout << "second num
";
        cin >> b;

        Calculator calt(op, a, b);

        cout << "result : " << calt.the_calculator() << endl;

        cout << "do you want to use it again?(Y/N)
";
        cin >> again;
        system("clear");   
    }
    system("clear");
    cout << "ok.. bye!
";
    sleep(2);
    system("clear");

    return 0;
}

Comment

how to make calculaor in c++

# include <iostream>
using namespace std;

int main() {
    char op;
    float num1, num2;

    cout << "Enter operator: +, -, *, /: ";
    cin >> op;

    cout << "Enter two operands: ";
    cin >> num1 >> num2;

    switch(op) {
        case '+':
            cout << num1 << " + " << num2 << " = " << num1 + num2;
            break;

        case '-':
            cout << num1 << " - " << num2 << " = " << num1 - num2;
            break;

        case '*':
            cout << num1 << " * " << num2 << " = " << num1 * num2;
            break;

        case '/':
            cout << num1 << " / " << num2 << " = " << num1 / num2;
            break;

        default:
            // If the operator is other than +, -, * or /, error message is shown
            cout << "Error! operator is not correct";
            break;
    }

    return 0;
}
Comment

calculator in cpp

#include <iostream>
using namespace std;
// Hi I'm Jillani Soft Tech. I'm a Developer.
main()
{
	while(true)
	{
		
		
		int sum,mul,sub,div;	// variable decalration
		int num1,num2;
		int choice;
		
		cout<<"

			----------Main Menu-----------"<<endl;
		
		cout<<"Press 1 for Sum "<<endl;
		cout<<"Press 2 for Sub "<<endl;
		cout<<"Press 3 for Mul "<<endl;
		cout<<"Press 4 for Div "<<endl;
		
		cout<<"
Enter Your Choice ? "<<endl;	
		cin>>choice;
		
		
		cout<<"Enter frist number : "<<endl;
		cin>>num1;
		cout<<"Enter Second number : "<<endl;
		cin>>num2;
		
		
		
		if(choice==1)
		{
			sum=num1+num2;
			cout<<"There sum is this : "<<sum<<endl;
		}
		else if(choice==2)
		{
			sub=num1-num2;
			cout<<"There sub is this : "<<sub<<endl;
		}
		else if(choice==3)
		{
			mul=num1*num2;
			cout<<"There mul is this : "<<mul<<endl;
		}
		else if(choice==4)
		{
			div=num1/num2;
			cout<<"There div is this : "<<div<<endl;
		}
		else
		{
			
			cout<<"

			Invalid Selection Try Again.... "<<endl;
		}
		
	}
}
Comment

c++ calculator

1 #include<stdio.h>
 2 
 3 int main(){
 4 
 5     char operator;
 6     double first, second;
 7 
 8     printf("Enter the Operator ( +, -, *, / ) : ");
 9     scanf("%c",&operator);
10 
11     printf("Enter the two Numbers one by one : ");
12     scanf("%lf %lf",&first,&second);
13 
14     switch (operator)
15     {
16 
17     case '+':
18         printf("%.2lf + %.2lf = %.2lf",first,second,(first+second));
19         break;
20         
21     case '-':
22         printf("%.2lf - %.2lf = %.2lf",first,second,(first-second));
23         break;
24 
25     case '*':
26         printf("%.2lf * %.2lf = %.2lf",first,second,(first*second));
27         break;
28 
29     case '/':
30         if( second != 0.0 )
31             printf("%.2lf / %.2lf = %.2lf",first,second,(first/second));
32         else 
33             printf("Divide by Zero situation");
34         break;
35     
36     default:
37         printf("%c is an invalid Operator",operator);
38         
39     }
40 
41     return 0;
42 }
Comment

PREVIOUS NEXT
Code Example
Cpp :: vector of threads thread pool c++ 
Cpp :: variables in c++ 
Cpp :: data types in c++ 
Cpp :: exponent of x using c c++ 
Cpp :: How to split a string by Specific Delimiter in C/C++ 
Cpp :: how to sort array in c++ stockoverflow 
Cpp :: walk filesystem in c++ 
Cpp :: sfml keyboard events cpp 
Cpp :: how to empty a std vector 
Cpp :: how to make a vector in c++ 
Cpp :: create new node in tree 
Cpp :: heredar constructor c++ 
Cpp :: makefile for single cpp file 
Cpp :: what is a variable in cpp 
Cpp :: C++ Arrays and Loops 
Cpp :: how to concatinate two strings in c++ 
Cpp :: how to print a word in c++ 
Cpp :: declare empty array in c++ 
Cpp :: tabeau pseudo dynamique sur c++ 
Cpp :: c++ define array with values 
Cpp :: c++ preprocessor commands 
Cpp :: queue operations c++ 
Cpp :: c++ class constructor variable arguments 
Cpp :: dynamic memory in c++ 
Cpp :: bubble sort function in c++ 
Cpp :: map of maps c++ 
Cpp :: codeforces problem 1030A solution 
Cpp :: crud with template c++ 
Cpp :: check if a string is a prefix of another c++ 
Cpp :: C++ Changing Default Value of Enums 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =