“calculatrice dans cpp” Réponses codées

calculatrice dans 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<<"\n\n\t\t\t----------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<<"\nEnter 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<<"\n\n\t\t\tInvalid Selection Try Again.... "<<endl;
		}
		
	}
}
Wicked Willet

comment faire du calculor en 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;
}
Talented Tuatara

Réponses similaires à “calculatrice dans cpp”

Questions similaires à “calculatrice dans cpp”

Plus de réponses similaires à “calculatrice dans cpp” dans C++

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code