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:
    #include <limits>
    
    {
    	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
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    have you included <limits>?
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    6
    Thank you for reply Stoned_Coder

    Yes

    #include <limits>

  4. #4
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    Posts
    317
    Code:
    #include<limits>
    #include<iostream>
    using namespace std;
    int main(void)
    {
        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');
    return 0;		}
    }
    This compiles and runs fine for me.
    "Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
    -- Cowper

    Operating Systems=Slackware Linux 9.1,Windows 98/Xp
    Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)

    You may teach a person from now until doom's day, but that person will only know what he learns himself.

    Now I know what doesn't work.

    A problem is understood by solving it, not by pondering it.

    For a bit of humor check out xkcd web comic http://xkcd.com/235/

  5. #5
    Registered User
    Join Date
    Apr 2005
    Posts
    6
    if I compile and run the program by it self like manofsteel972 did, it works fine like he said. but when I included that to my program, wich is about 600 lines, I get the error. I'm using this files:

    #include <iostream>
    #include <ctime>
    #include <stdlib.h>
    #include <cmath>
    #include <iomanip.h>
    #include <conio.h>
    #include <stdio.h>
    #include <windows.h>
    #include <string>
    #include <limits>

    I think one of those files is the problems, but I need for the others function in the program.

    Is there another way to do it? I have been working in this part for hours. I tried everything.

    Help please!!

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