Error Check.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jackly84
    New Member
    • Mar 2010
    • 16

    Error Check.

    ok, I am after looking Every Where and can't seem to find any code on this.

    how do i stop a user from Entering in the Same number twice ?
    Code:
    	while((cout<<"Enter Student Number: ")&&(!(cin>>record[n].student_number)||record[n].student_number<0)){
                cout<<"Invalid Input!"<<endl;
                cin.clear();
                cin.ignore(1000,'\n');
    For Student ID, i dont want user to be able to Enter the Same Student ID for different names.
  • mac11
    Contributor
    • Apr 2007
    • 256

    #2
    If they put in a number you don't want just drop that number and ask for another. It looks like you're kind of half way there.

    hints:
    - don't try to abuse cin by using ignore and clear just read everything they enter
    - the while condition is way too complex, try splitting that work out into the while body and make the condition simple

    Comment

    • jackly84
      New Member
      • Mar 2010
      • 16

      #3
      My other Error check if to make sure they Enter a Number..

      but what if i enter 1232 for one ID, 23232 for the next and then in my 3rd Record enter 1232, how can i tell the User that this is taken ?

      Comment

      • whodgson
        Contributor
        • Jan 2007
        • 542

        #4
        You could enter the number (ID) into a vector or array and then loop through the array to establish if it has an element with the same value.

        Comment

        • jackly84
          New Member
          • Mar 2010
          • 16

          #5
          I have it going into an Array..
          But how do i loop over the array to peak into the array to see if i have or have not enter that ID..

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            Write a function.

            Call it using the number entered,the address of your array and the number of elements. Have the function return true if the number was found and false otherwise.

            Comment

            Working...