infinite loop

This is a discussion on infinite loop within the C Programming forums, part of the General Programming Boards category; my program enter an infinite loop if the user inputs invalid data? I check the FAQ section and I got ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    6

    infinite loop

    my program enter an infinite loop if the user inputs invalid data?

    I check the FAQ section and I got this code, I say super I fix my problem, but when I try to run my program I get 3 errors:

    Code:
    {
    	int a = 0;
    	while (cout << "Please Enter the Number of Clases Compleated: " && !(cin >> a))
    		{
    		 cout << "\nInvalid input" <<endl;
    		 cin.clear();
    		 cin.ignore(std::numeric_limits <int>::max(), '\n');
    		}
    
    	cout << "\n";
    	if (a < 2)
    		info[j].clas[0] = 'C';
    	else if (a>=2 && a<=4)
    		info[j].clas[0] = 'B';
    	else if (a>4)
    		info[j].clas[0] = 'A';
    	info[j].clas[1] = '\0';
    }
    -not enough actual parameters for macro 'max'
    -error C2589: '(' : illegal token on right side of '::'
    -error C2143: syntax error : missing ')' before '::'
    -error C2059: syntax error : ')'

    Please help, the project is due next week. everything work but this section.

  2. #2
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    Please relocate this thread to the c++ board.


    thank you.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    It looks good to me, but you may need to include limits:
    Code:
    #include <limits>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 06-15-2009, 12:24 AM
  2. Cosine fucntion and infinite loop.
    By youareafever in forum C Programming
    Replies: 2
    Last Post: 11-07-2008, 04:45 AM
  3. Infinite Loop with GetAsyncKeyState
    By guitarist809 in forum Windows Programming
    Replies: 1
    Last Post: 04-18-2008, 01:09 PM
  4. Switch statement = infinite loop
    By Lucid003 in forum C++ Programming
    Replies: 10
    Last Post: 10-10-2005, 01:46 AM
  5. stays in loop, but it's not an infinite loop (C++)
    By Berticus in forum C++ Programming
    Replies: 8
    Last Post: 07-19-2005, 12:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21