Thread: continue problems in array

  1. #1
    Registered User
    Join Date
    Feb 2006
    Location
    Wichita, KS
    Posts
    6

    continue problems in array

    below is a portion of my program. Any assistance is greatly appreciated.

    essentially, i am trying to use this loop structure to assign values for a 1x20 array. Values must conform to the range restrictions (10<=x<=100). Also, if user enters number outside of range, i want a continue function to repeat the loop without incrimentation of the loop integer "i". If value conforms to restrictions, it should be stored in the array and the value will be printed.

    Code:
    for (i=0;i<=19;i++);
     {
     printf("Enter number between 10 and 100:");
     scanf("%f", ar[i]);
      if (ar[i]<10||ar[i]>100)
       printf("\nInvalid number, not within the specified range");
       continue;
      else
       printf("%d",i);
     }

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Always use full bracing for code blocks.

    But you probably don't want the loop increment if you don't get a valid value.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > for (i=0;i<=19;i++);
    Watch that final ;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 05:48 PM
  2. Problems passing an array to a function
    By ndenklau in forum C Programming
    Replies: 5
    Last Post: 09-20-2006, 08:14 AM
  3. problems finding the average of an array column
    By mrgeoff in forum C Programming
    Replies: 4
    Last Post: 04-18-2005, 11:49 PM
  4. Creating 2D arrays on heap
    By sundeeptuteja in forum C++ Programming
    Replies: 6
    Last Post: 08-16-2002, 11:44 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM