Thread: Console Calc
View Single Post
Old Sep 15th, 2005, 9:44 AM   #5
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
Same Output. Code reduced by 1/2
// User: ViOLATiON
// Date: September 15th, 2005
// Comments: Basic Calculator
#include <iostream>
using namespace std;
int main()
{
    int opchoice;
    int numberone;
    int numbertwo;
    int answer;
    // Choose your operation
    cout<<"Choose your operation\n\n1 - Multiplication\n2 - Subtraction\n3 - Addition\n4 - Division\n\n"<<endl;
    cin>>opchoice;
	
	cout<<"\nPlease input the first number\n\n";
    cin>>numberone;
    cin.get();
    cout<<"\n\nPlease input the second number\n\n";
    cin>>numbertwo;
	cin.get();

	switch(opchoice)
	{
	case 1: 
		// Multiplication
       answer = numberone * numbertwo;
	   break;
	case 2:
	   // Subtraction

		answer = numberone - numbertwo;
		break;
    // Addition
    case 3:
		answer = numberone + numbertwo;
		break;    
	case 4:
		//division
		answer = numberone / numbertwo;

	}
    cout<<"\nThe final answer is "<<answer << "\n";
    cin.get();
    return 0;
    
}
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote