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 :: for loop with array c++ 
Cpp :: how to install boost c++ on windows 
Cpp :: c++ random number 0 to 1 
Cpp :: prime numbers less than a given number c++ 
Cpp :: insert vector to end of vector c++ 
Cpp :: random number generator c++ between 0 and 1 
Cpp :: max of a vector c++ 
Cpp :: SetUnhandledExceptionFilter 
Cpp :: how to create array with not constant size in cpp 
Cpp :: vector.find() 
Cpp :: c++ create multidimensional vector 
Cpp :: primes in range cpp 
Cpp :: create file c++ 
Cpp :: how to convert string into lowercase in cpp 
Cpp :: c++ program transpose of matrix 
Cpp :: delete specific row from dynamic 2d array c++ 
Cpp :: remove decimal c++ 
Cpp :: C++ structure (Struct) 
Cpp :: priority queue c++ 
Cpp :: c++ keyboard input 
Cpp :: int to hexadecimal in c++ 
Cpp :: sort a vector c++ 
Cpp :: what is a template in c++ 
Cpp :: min heap priority queue c++ 
Cpp :: hexadecimal or binary to int c++ 
Cpp :: argument vs parameter coding c++ 
Cpp :: sum of row s2 d array c++ 
Cpp :: opengl draw semi circle c++ 
Cpp :: how to use custom array in c++ 
Cpp :: cpp array init value 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =