C++ Program to implement calculation on any entered two numbers
#include <iostream.h>
#include <conio.h>
float a;
float b;
float result;
int op;
int option;
int main()
{
do
{
cout << "Enter First Number \n";
cin >> a; // Input
cout << "Enter Second Number \n";
cin >> b;
cout << "Please enter an Option..\n";
cout << "[1] Add \n";
cout << "[2] Substract \n";
cout << "[3] Multiply \n";
cout << "[4] Devide \n ";
cin >> op; // The keybord input is passed to variable 'op'
switch (op)// switch is similar to Select Case in VB
{
case 1 : // Case Addition
result=a+b;
break;
case 2 : //Case Substraction
result=a-b;
break;
case 3 : // Case multiplication
result=a*b;
break;
case 4 : // Case Division
result=a/b;
}
cout <<"The Result is..= " << result << "\n\n"; //Display Result and Skipping two Lines
cout << "Enter an Option..\n";
cout << "[0] Exit.\n";
cout << "[1] Continue. \n";
cin >> option;
// Do While loop Ends Here
} while (option==1); // If option is 1 ie 'Continue' the above code is Looped else ( option<>1 ) it is Escaped from Loop
return 0;// the ' main' function returns value 0
}
Related Posts : C++ Programs
0 comments:
Post a Comment