so ive only recently started trying to learn c++
i did as many of the tutorials as i could figure out from this site, now i have been going through the forums and just trying out different code that people ask about and stuff
so i read several threads on making a password show up as * and i tried to piece one together for myself this is what i have so far, but it isn't working quite right and i am not "learned" enough to figure out why input would be great
Code:
#include <iostream>
#include <string>
#include <windows.h>
#include <conio.h>
using std::cout;
using std::endl;
using std::cin;
using std::string;
int main(){
char ch;
string password;
int counter = 0;
int maxlength;
char pword[10];
cout<<"Password: ";
while( (ch = getch() ) != '\r' && counter < maxlength-1 ){
if(ch == '\b' && counter > 0){
cout<<("\b \b");
counter--;
}
else{
pword[counter++] = ch;
putchar('*');
}
pword[counter] = '\0';
}
cin>> password;
cin.get();
if (password == "1234567"){
cout<<"Welcome\n";
}
else {
cout<<"Forbidden\n";
}
cin.get();
}