password censoring problem . Help the noob. Please

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream.h>
#include<conio.h>
#include<string.h>
using namespace std;
int main()
{
    char a[20];
    int b;
    string d="abcd";
    for(b=1;(b<=4);++b)
    {
                       cin>>a[b];
                       cout<<"\b"<<"*";
                       }
                       if(a[0, 1, 2, 3, 4]==d)
                       cout<<"ya";
                       else
                       cout<<"no";
    getch();
    return 0;
}


Hey , you must have assumed my intention to write the program.
well, i simple want the user to write a password, but while writing.. the alphabets should be replaced with *...
But i am getting some errors.
I am sorry if you think that the program is too stupid.
Actually i am not learning c++ "legally" as i am too young for it (15). i am just reading manuals and watching youtube tutorials... due to my infinite interest in programming. :D
i am using dev c++ (4.0.92) [it suxx]
please help!
Thank you
Last edited on
On line 15 you are trying to access multiple positions within the array. You cannot do this. char variable a is an array of 20 items, and if you want to access positions 0, 1, 2, 3, or 4 you will need to re write the code as follows:

1
2
3
4
if(a[0] == 'd' && a[1] == 'd' && a[2] == 'd' && a[3] == 'd' && a[4] == 'd')
cout<<"ya";
else
cout<<"no.";

also note that I placed your comparison rvalue within apostrophes, and not quotes. This is because you are comparing single chars, and not strings.

Your for loop needs to start at zero, and not 1. The first position within an array is always zero, not one.
Topic archived. No new replies allowed.