Thread: Problems W/Cin?

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Question Problems W/Cin?

    Ok, I'm working on an NPC Library for future use and I've come across trouble. Here's the function code:

    Code:
    NPC::CLS_FIND()
    {
    	clsno=0;
    	while(clsno<1||clsno>3)
    	{	
    		system("cls");
    		cout << "How many classes?" << endl;
    		cin >> clsno;
    		cout << endl;
    		if(clsno<1||clsno>3)
    		{
    			cout << "Invalid Number of Classes!" << endl;
    			cout << "Must Be Between 1-3!" << endl;
    			getch();
    		}
    	}
    	lp=0;
    	while(lp!=clsno+1)
    	{
    		system("cls");
    		if(lp==1)
    		{
    			cout << "What is Class 1?" << endl;
    			cin >> cls1;
    		}
    		else if(lp==2)
    		{
    			cout << "What is Class 2?" << endl;
    			cin >> cls2;
    		}
    		else if(lp==3)
    		{
    			cout << "What is Class 3?" << endl;
    			cin >> cls3;
    		}
    		lp++;
    	}
    	return 0;
    }
    The execution stops after the second cin, why?

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    1

    Exclamation ...

    peace love and joy are happy good things that everyone should support. i wish you only the absolute best of luck on your assignment!!

    Let the happy blooming flowers make your day wonderfully smilingful.

  3. #3
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    try adding:

    Code:
    cin.ignore();
    after you get input.

  4. #4
    In The Light
    Join Date
    Oct 2001
    Posts
    598
    howdy,
    WOW lala that was brilliant.

    M.R.
    I don't like you very much. Please post a lot less.
    Cheez
    *and then*
    No, I know you were joking. My point still stands.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  5. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM