Thread: Basic Calculator I made check it out if you want...

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,337
    A few tweaks
    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
    	const string HEADER ( "\t\t\tBasic Calculator Program\n\n" );
    	const string SUBHEAD ( "\t\t\tEnter in a math problem\n\n" );
    	const string line ( 80, '*' );
    	float FirstNumber; 
    	char  op ; 
    	float SecondNumber; 
    	float Total;
    
    	cout.precision(4);
    
    	cout << line << endl << endl;
    	cout << HEADER << SUBHEAD << line << endl;
    
    	while ( true ) {
    
    		cout << ">";
    		cin >> FirstNumber >> op >> SecondNumber;
    
    		switch ( op ) 
    		{
    
    		case '-':
    
    			Total = FirstNumber - SecondNumber ;
    			break;
    
    		case '+':
    
    			Total = FirstNumber + SecondNumber ;
    			break;
    
    		case '*':
    		case 'x':
    		case 'X':
    
    			Total = FirstNumber * SecondNumber ;
    			break;
    
    		case '/':
    
    			if ( SecondNumber == 0 ) 
    			{
    				cout << "\n\"Error you can't / by 0\" \n\n";
    				continue;
    			} 
    
    			Total = FirstNumber / SecondNumber ;
    			break;
    
    		default:
    
    			cout << "\n\"Error you can't do that \"\n\n";
    			cout << "Try again.\n\n";
    			continue;
    		}
    		
    		
    		cout << "\n" << FirstNumber << " " << op << " " << SecondNumber << " = " << Total << "\n\n";
    
    	}
    
    	system("pause");
    	return(0);
    }
    Mainframe assembler programmer by trade. C coder when I can.

  2. #2
    Registered User Sshakey6791's Avatar
    Join Date
    Nov 2008
    Location
    -
    Posts
    57
    I like it. Thanks for checkout my program..... Thanks for the help, Both of you
    "Blood you have thirsted for -- now, drink your own!"
    (Dante)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. how to put a check on an extern variable set as flag
    By rebelsoul in forum C Programming
    Replies: 18
    Last Post: 05-25-2009, 03:13 AM
  3. visual basic vs C or C++
    By FOOTOO in forum Windows Programming
    Replies: 5
    Last Post: 02-06-2005, 08:41 PM
  4. Visual Basic Adodc Problem
    By rahat in forum Windows Programming
    Replies: 1
    Last Post: 01-20-2002, 06:55 AM