0

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]);

    }

}

Edited by Ng

2
Contributors
3
Replies
14
Views
3 Years
Discussion Span
Last Post by Learner010
0

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;
        }
    }
}

Edited by Learner010

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.