VB icon

A Simple Calculator

Email
Submitted on: 1/2/2015 10:59:00 PM
By: Saifudheen A A (from psc cd)  
Level: Beginner
User Rating: By 7 Users
Compatibility: C++ (general), Microsoft Visual C++, Borland C++, UNIX C++
Views: 1208
 
     A simple Calculator ; Well Commented easy to follow, for beginers. It also shows some basics of C++ programs. If you find this article helpful to you please send me a message.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: A Simple Calculator
// Description:A simple Calculator ;
Well Commented easy to follow,
for beginers.
It also shows some basics of C++ programs. If you find this article helpful to you please send me a message.
// By: Saifudheen A A (from psc cd)
//
// Side Effects:As the program will not make any error check, Dont enter any charactors other than numbers.
//**************************************

// This is a comment an will not make any sense to program
// Simple Calculator By A. A . Saifudheen
// keraleeyan@msn.com
// This Code is NOT copywrited and may distribute
// freely unless any comments are NOT Removed including above comments
#include <iostream.h> // This file used for function definitions 'cout' and 'cin' in program
//Simple Calculator By A. A . Saifudheen
float a; // floating point variable -Means a Variable that capable of storing a number having some decimal places
float b; // 
float result; 
int op; // Integer Variable -Means Variable that capable of storing a number. ( No decimal places)
int option;
int main() // It is the main function. A function Named 'main' is required for all C++ programs
{
	do //'Do While' loop Used for Looping the program for multiple Calculations
	// 'Do While' loop Starts Here
	{	
		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 ";	
		
		// Add more function like Power, Modulus etc if needed.
		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
	}
// End of Code


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.