0% found this document useful (0 votes)
22 views

Oops-Program 3-Mdu

The program requests a number, operator, and another number from the user and performs the specified arithmetic operation. It uses a switch statement to select addition, subtraction, multiplication, or division and displays the result. The program then asks if the user wants to do another calculation.

Uploaded by

Atul Malhotra
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Oops-Program 3-Mdu

The program requests a number, operator, and another number from the user and performs the specified arithmetic operation. It uses a switch statement to select addition, subtraction, multiplication, or division and displays the result. The program then asks if the user wants to do another calculation.

Uploaded by

Atul Malhotra
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

C++ Programming Lab File Name: program3.

cpp

PROGRAM NO. 3
Objective: - Create the equivalent of a four function calculator. The program should request the user
to enter a number, an operator, and another number. It should then carry out the specified arithmetical operation: adding, subtracting, multiplying, or dividing the two numbers. (It should use a switch statement to select the operation). Finally it should display the result. When it finishes the calculation, the program should ask if the user wants to do another calculation. The response can be Y or N. Some sample interaction with the program might look like this: Enter first number, operator, and second number: 10/ 3 Answer = 3.333333 Do another (Y/ N)? Y Enter first number, operator and second number 12 + 100 Answer = 112 Do another (Y/ N)? N

#include<iostream> using namespace std; int main() { float a,b,c; char x,z; do { cout<<"Enter first number,operator,second number:"; cin>>a>>x>>b; switch(x) { case '+':c=a+b; cout<<"Answer="<<c; break; case '-':c=a-b; cout<<"Answer="<<c; break; case '/':c=a/b; cout<<"Answer="<<c; break; case '*':c=a*b; cout<<"Answer="<<c; break; default :cout<<"wrong choice"; break; } cout<<"\nDo another(y/n)?:"; cin>>z; }while(z=='y'); return 0; }

//header file //main() function //variable declaration

//switch statement

//end of main()

SBIT/CSE/IV/C++ PROGRAMMING/CSE-206-F

CSE/10/409

C++ Programming Lab

OUTPUT

SBIT/CSE/IV/C++ PROGRAMMING/CSE-206-F

CSE/10/409

You might also like