Hi , i'm using vectors for the first time in a project , my project about Bnking system , my idea is the user enter a name and the program will search for it in the vector same as the password , How can code this ?
I try and this what i have so far . a lot of red lines in the code and i dont know why and who to fix it .
#include<conio.h>
#include <vector >
#include<string.h>
usingnamespace std ;
int main () {
int index;
vector<string>names;
vector<int>passwords;
vector<int>account;
vector<string>::const_iterator i;
names.push_back("mohammad");names.push_back("Khaled");names.push_back("Ahmmad");
passwords.push_back(3421);passwords.push_back(1416);passwords.push_back(2776);
account.push_back(800);account.push_back(1000000);account.push_back(5000);
char answr;
cout<<" Do you have account ? y\n";
cin>>answr;
if ( answr =='y'||'Y')
{
cout<<"Enter your name : "<<endl;
char name;
cin>>name;
for( i=names.begin();i!=names.end();i++)
{
if (names at.(i)==name)//
index=i;
}
while(1)
{
char password ;
cout<<"ENTER YOUR PASSOWRD :\n";
cin>>password;
if(password==passwords at.[index])//
{cout<<"loge in is completed";
break;}
else
cout<<"the name dosn't match the password ,try again";
}
yeah i found errors and c corrected it , it worked fine but when i enter the name and the password every time it give me the else statement.
I'm using Microsoft Visual 2010 Express
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
int main()
{
std::vector<std::string> names ;
names.push_back( "mohammad" ) ; names.push_back( "khaled" ) ; names.push_back( "ahmmad" ) ;
std::vector<int> passwords ;
passwords.push_back(3421) ; passwords.push_back(1416) ; passwords.push_back(2776) ;
assert( passwords.size() == names.size() ) ;
for( std::size_t i = 0 ; i < names.size() ; ++i )
std::cout << i << ". " << names[i] << ' ' << passwords[i] << '\n' ;
// std::cout << "name? " ;
std::string user_name ;
user_name = "khaled" ; // std::getline( std::cin, user_name ) ;
// std::cout << "password? " ;
int pword ;
// std::cin >> pword ;
pword = 1416 ;
std::cout << "\nsearching for user name '" << user_name << "' with password " << pword << '\n' ;
// find the position corresponding to the name
std::size_t pos ;
for( pos = 0 ; pos < names.size() && names[pos] != user_name ; ++pos ) ;
if( pos < names.size() ) std::cout << "user name '" << user_name << "' was found at position " << pos
<< "\npassords[" << pos << "] is " << passwords[pos] << "\n\n" ;
// if the name was found, pos would be less than names.size()
if( pos < names.size() && passwords[pos] == pword ) std::cout << "login successful\n" ;
else std::cout << "invalid name/password\n" ;
}
0. mohammad 3421
1. khaled 1416
2. ahmmad 2776
searching for user name 'khaled' with password 1416
user name 'khaled' was found at position 1
passords[1] is 1416
login successful