sentinel logic

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • knviesky
    New Member
    • Apr 2007
    • 1

    sentinel logic

    "Write a program that will read in integers from the keyboard and decide if the numbers are all the same or not. Use sentinel logic with a 9999 as the sentinel value. Use a flag. Note that you do NOT know how many numbers there will be in the input. If there is only one number, then consider that yes, they are "all" the same. Print your source code."
    how would i make it able to read unlimited integers?
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You don't have to "make" it read unlimited numbers, the C/C++ command line argument code will automatically handle that for you.

    This page seems to explain it quite well, the main function is called with 2 parameters, the count of the number of command line arguments and a pointer to an array of the command line arguments.

    Code:
    int main(int argc, char **argp)
    {
        return 0;
    }
    Note that the first command line argument argp[0] is always the name of the program as invoked. To read unlimited numbers all you have to do is process all the other command line arguments.

    Comment

    Working...