condition in in array(for loope)

This is a discussion on condition in in array(for loope) within the C Programming forums, part of the General Programming Boards category; I have a problem with condition with what should go into array. Array(Student),i,n was declared as int , and it ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    8

    Exclamation condition in in array(for loope)

    I have a problem with condition with what should go into array.
    Array(Student),i,n was declared as int , and it works perfect with numbers, but if I enter any letter or some other sign (, . ; : " ' etc.) the program does not goes to "goto" but just displays error message "You have entered invalid grade,\nplease enter value for the grade from the interval\nwich begins with 5 and ends with 10" and when I press any key the program just displays that message again and again.

    Does anywhone knows how to fix this ?

    Thank You for your patience.

    code is

    Code:
    for(i=0;i<n;i++)
    	{
    	
    TryAgain:printf("enter value for the %d grade : ",i+1);
    		scanf("%d",&Student[i]);
    		if(Student[i]<5||Student[i]>10)
    		{
    			printf("You have entered invalid grade,\nplease enter value for the grade from the interval\nwich begins with 5 and ends with 10\n\n");
    			system("pause");
    			system("cls");
    			goto TryAgain;
    		}
    
    	}

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185

  3. #3
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    507
    While goto is great for teaching programming ideals and constructs ie looping....C provides much cleaner/more maintainable constructs for such a thing. I would recommend asking whoever told you to use goto what other loop control constructs are available (for, do while, while etc..) and why they suggested you use goto to begin with.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mutex, Cond and Thread questions (pthread, linux)
    By thebearot in forum C Programming
    Replies: 14
    Last Post: 04-23-2010, 01:10 PM
  2. Condition variables
    By sethjackson in forum Windows Programming
    Replies: 16
    Last Post: 03-19-2008, 12:42 PM
  3. SDL Condition variables.
    By antex in forum Game Programming
    Replies: 3
    Last Post: 11-11-2005, 07:11 AM
  4. Looping condition
    By Chaplin27 in forum C++ Programming
    Replies: 3
    Last Post: 05-29-2005, 03:06 PM
  5. Race condition
    By Roaring_Tiger in forum C Programming
    Replies: 5
    Last Post: 10-24-2004, 10:42 PM

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