Computer Science, asked by aryansinghrajput119, 2 months ago

write a program in c++ to make a visual offline calculator​

Answers

Answered by Aryansingh001
4

Explanation:

# 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; }

Output

Enter operator either + or - or * or divide : - Enter two operands: 3.4 8.4 3.4 - 8.4 = -5.0

Thi

Answered by kimtaehyung35
4

Answer:

#include <stdio.h>

int main(){

char wish;

float num1,num2,result;

int flag =1;

printf(" Enter - , + , * ,/ for knowing result \n");

scanf("%c" , &wish);

printf ("Enter number 1\n");

scanf("%f", &num1 );

printf ("Enter number 2\n");

scanf("%f" , &num2 );

switch (wish)

{

case '+':

result =num1+num2;

break ;

case'-':

result =num1-num2;

break ;

case '/':

{

if (num2 ==0)

{

flag = 0;

}

else

{

result =num1/num2;

}

break ;

}

case'*':

result = num1 *num2;

break ;

default : printf ("error");

break ;

}

if (flag ==1)

{

printf ("%f %c %f =%f" , num1, wish,num2 ,result );

}

else

{

printf ("%f %c %f = undefined" ,num1 ,wish ,num2 );

}

}

credit my sister niki : /c6KolmU1s7oC/#c

Explanation:

Similar questions