-
need some help
i have been asked to solve the following problem
Make a list of pin numbers. Prompt a user for his pin number. If he has entered a valid pin number it, display the message “Welcome to the system. Your pin number is verified”. After that it should give the user options to check his balance as well. If it is not among the valid pin number list, display that “your pin is not verified”. Ask user to enter again. One user can try only 3 times. the program should not get crashed if a character is entered instead of a number.not allowed to use any loops , use only variables
i did some coding but i am stuck on how to make the program work in the three invalid tries area...and also the program crashes if i use a character
#include<iostream.h>
void main()
{
int a,b,c,d,e,f,g,h,i,j,pin,x,y;
a=1234;
b=2345;
c=5321;
d=5674;
e=8753;
f=1237;
g=9456;
h=3467;
i=9128;
j=5190;
x=0;
cout<<"Enter the pin number :";
cin>>pin;
if((x=0) && (pin==a||pin==b||pin==c||pin==d||pin==e||pin==f||p in==g||pin==h||pin==i||pin==j))
{
cout<<"Welcome to the system. Your pin number is verified"<<endl;
cout<<"check your balance"<<endl;
}
else if (pin!=a||pin!=b||pin!=c||pin!=d||pin!=e||pin!=f||p in!=g||pin!=h||pin!=i||pin!=j)
{ cout<<"your pin is not verified"<<endl;
cout<<"Enter the pin number :";
cin>>pin;
x++;
}
if
((x=1) && (pin==a||pin==b||pin==c||pin==d||pin==e||pin==f||p in==g||pin==h||pin==i||pin==j))
{
cout<<"Welcome to the system. Your pin number is verified"<<endl;
cout<<"check your balance"<<endl;
}
else if (pin!=a||pin!=b||pin!=c||pin!=d||pin!=e||pin!=f||p in!=g||pin!=h||pin!=i||pin!=j)
{ cout<<"your pin is not verified"<<endl;
cout<<"Enter the pin number :";
cin>>pin;
x++; }
if
((x=2) && (pin==a||pin==b||pin==c||pin==d||pin==e||pin==f||p in==g||pin==h||pin==i||pin==j))
{
cout<<"Welcome to the system. Your pin number is verified"<<endl;
cout<<"check your balance"<<endl;
}
else if (pin!=a||pin!=b||pin!=c||pin!=d||pin!=e||pin!=f||p in!=g||pin!=h||pin!=i||pin!=j)
{ cout<<"your pin is not verified"<<endl;
cout<<"Enter the pin number :";
cin>>pin;
x++; }
}
-
well, first things first you need to do the following in the order specified:
1. think of a better thread title than "need some help". it's very non-descriptive, and doesn't give the reader any idea what you need help with.
2. put code tags around your code so that it shows up formatted properly.
now, on to your problem.
my first suggestion would be to put all of the valid PINs in an array such as:
Code:
int pin_array[] = { 1234, 2345, 5321, 5674, 8753, 1237, 9456, 3467, 9128, 5190 };
perhaps you could have some kind of identifier at the end of the array (such as -1) to indicate that it's the end. then you can loop through the array until you find the identifier, and break out of the loop when the identifier is found. if the PIN the user entered is found inside the loop, you can give feedback to the user that it was found. if not, tell them that they entered an invalid PIN.