C++ Programming How to Make a Simple Calculator
This program will show you to how to make simple Calculator using if/else statement in C++ Language.
Program # 3 : Calculator using if/else statement
#include <iostream>
using namespace std;
int main()
{
float a, b;
char c;
float R;
cout << "Enter the First Number : \n";
cin >> a;
cout << "Enter the Second Number : \n";
cin >> b;
cout << "*****What to do?***** \n" << "+ For Addition \n" << "- For Subtraction \n" << "* For Multiplication \n" << "/ For Division \n " ;
cin >> c;
if(c=='+' )
{
R = a + b;
cout << R;
}
else if(c=='-')
{
R = a - b;
cout << R;
}
else if (c=='*')
{
R = a * b;
cout << R;
}
else if(c=='/')
{
R = a / b ;
cout << R;
}
else
cout << "Invalid operator ";
return 0;
}
Output Of the Program :
Watch This Video
0 comments:
Post a Comment