Thread: switch case

  1. #16
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I think RealityFusion just made a typo. Nobody else argued one way or the other, so there is nobody else to believe. To use char, just replace the word int with the word char in the example code.

  2. #17
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    the code wont work
    ive tried a bunch of things i dont get it

  3. #18
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    
    {
    
    
    	char type_of_calculation;
    
    	cout << "Calculator:" << endl;
    	cout << "Enter A for addition of two numbers, D for divison of two numbers: ";
    	cin >> type_of_calculation;
    
    	switch (type_of_calculation)
    	{
    
    	case 'a':
    	case 'A':
    		
    		double value1, value2;
    
    		cout << "Enter the first of two numbers to add: ";
    		cin >> value1;
    		cout <<"second number: ";
    		cin >> value2;
    		cout << endl << value1 << " + " << value2 << " = " << (value1 + value2) << endl;
    
    			//Or however/whatever you wanted to do.
    	
    
    		break;
    		
    
    	case 'd':
    	case 'D':
    
    		double dividend, divisor;
    
    		cout << "Enter the dividend: ";
    		cin >> dividend;
    		cout <<"now the divisor: ";
    		cin >> divisor;
    		cout << endl << dividend << " / " << divisor << " = " << (dividend / divisor) << endl;
    
    
    			//Or however/whatever you wanted to do.
    
    		break;
    		
    		
    	}
    
    	system("pause");
    
      return 0;
    
    
    }
    That should get you started....
    Payment for services rendered is next time you want help and ask a question take a little more time writing it and use capitalization and punctuation please!
    Last edited by Enahs; 09-21-2005 at 08:21 PM.

  4. #19
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Enahs' example might not compile with Dev-C++, but the idea is there. If you are having problems, post the code you are trying.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 08:55 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. Replies: 27
    Last Post: 10-11-2006, 04:27 AM
  4. Problems with switch()
    By duvernais28 in forum C Programming
    Replies: 13
    Last Post: 01-28-2005, 10:42 AM
  5. rand()
    By serious in forum C Programming
    Replies: 8
    Last Post: 02-15-2002, 02:07 AM