-1

How can i possibly use array to create a password program?

#include <iostream>
using namespace std;

main()
{

 int password[5] = {1,2,3,4,5};
        int pass[5];

        cout << "enter pass: ";
        cin >> pass[5];

        if(pass[5] == password[5])
        {
        cout <<"hey";
        }
        else
        {
        cout << "error";
        }
}
2
Contributors
1
Reply
17
Views
3 Years
Discussion Span
Last Post by Learner010
0

first off, a few things :
are you really using number as password ? if yes then consider following things :-

An Array Arr[5] will consist 5 values from 0 to 4 index hence there will be nothing in Arr[5]. ok.

cout << "enter pass: ";
cin >> pass[5];

by doing so , you are getting value at the fifth index of pass array which is not valid(because we can access elements from 0 to size-1 values) .However the statement will not throw any error but i don't think its valid. if you want to create a program to check password then i think this can be achieved without using Array. Look at this :-

int x,y;
x=12345;
cin>>y;
if(x==y)
cout<<"Password is valid";
else
cout<<"Password incorrect";

also consider other data types as your requirments(if you need password around 10 character long) then use of string or array.

Edited by Learner010

This topic has been dead for over six months. 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.