Thread: how can i make this work?

  1. #1
    Registered User
    Join Date
    Jul 2008

    how can i make this work?

    using namespace std;
    int main()
        string option;
        cout << "What Would You Like To Do?" << endl;
        cout << "To Withdraw Please Type withdraw" << endl;
        cout << "To Deposit Please Type  deposit" << endl;
        cin >> option;
        switch (option)
               case 'withdraw':
                    cout << "hi" << endl;
               case 'deposit':
                    cout << "bye" << endl;
                    cout << "NO" << endl;
         return 0;
    I want to make a little bank program but i keep getting an error....whats the problem?

  2. #2
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Read your compiler's output - it should tell you that you can't use strings in switch statements - you have to use a simpler type. My suggestion would be to use a character or an integer, e.g. for withdrawals, enter 1, and in the switch statement have a case which handles that value. Your variable called option should be changed to an integer to do this.
    No No's:
    fflush (stdin); gets (); void main ();

    Example of fgets (); The FAQ, C/C++ Reference

    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition

    ASCII stupid question, get a stupid ANSI

  3. #3
    Registered User
    Join Date
    Oct 2001
    You can't use strings in a switch and string literals have " around them, not '.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Makefile Problem: None rule to make target
    By chris24300 in forum Linux Programming
    Replies: 25
    Last Post: 06-17-2009, 09:45 AM
  2. Game Programming FAQ
    By TechWins in forum Game Programming
    Replies: 5
    Last Post: 09-29-2004, 02:00 AM
  3. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  4. cant make it work
    By papous27 in forum Linux Programming
    Replies: 0
    Last Post: 03-05-2002, 08:49 PM
  5. how to make files
    By quiksilver9531 in forum C++ Programming
    Replies: 6
    Last Post: 02-22-2002, 05:44 PM
Website Security Test