I am doing data validation.

Assume i type 3 student ID:

First:1234
Second:4567
Third:1234 (same ask the user to type student id again)

Please give me some hints,how can i do the part of checking the all data the user type? (whether have already exit).
Thanks.

#include<stdio.h>
int main()
{
    int Num;
    printf("Enter a number for student:"); //enter the number of student
    scanf("%d",&Num);
    int i;
    int myArr[Num];
    for(i=0;i<Num;i++)
    {
        printf("\n\nEnter student ID:");//type the StudentID
        scanf("%d",&myArr[i]);

    }

}

try logic like this:

for(i=0;i<3;i++)
{
    //code for getting input to arr[i]
    for(int j=0;j<i;j++)
    {
        if(arr[i]==arr[j])
        {
        cout<<"value already exist";
        i--;    //so that you can insert again at the same index
        break;
        }
    }
}

Thanks you very much .

mark this thread solved.

happy coding.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.