Page 1 of 1

C++ need help !

Posted: Sun Feb 13, 2011 9:35 pm
by lemonnutz
Guys.. I need help for my project >< i cant solve it ><
Question is ->

"Write a program to enter ask user to enter a 6 to 10 character password. Print valid
if the password has at least two digits, one upper case letter, one punctuation sign and the first letter start with 6. If invalid, print an error message to explain to the user why it is invalid.
"

punctuation sign mean symbol eg. [~!@#$%^&*()_]

i really cant think of any code can solve this question >< hope you guys might help me TT

Re: C++ need help !

Posted: Sun Feb 13, 2011 10:22 pm
by Nerrazzuri
Why don't you show us what have you done?
This isn't hard, and I can give the solution to you but if you're just requesting something that you're lazy to do, then sorry.

Re: C++ need help !

Posted: Sun Feb 13, 2011 10:31 pm
by lemonnutz
i am new to c++ ><
but i could not think of the code tat how to let the cin value must contain those requirement ..

i made myself the code...but is wrong...so i delete it ...

i still remember with using #include <cstring>, and the cin i use cin.getline();

><

Re: C++ need help !

Posted: Sun Feb 13, 2011 11:09 pm
by Nerrazzuri
You are requesting someone to help you finish your work, and that will not be me. If you want someone to help you, show your unfinished work and we will try to fix it for you.

Tips: use standard string and check using a loop.

Re: C++ need help !

Posted: Sun Feb 13, 2011 11:23 pm
by lemonnutz
ya..is my un-finish work..coz i don't know how to do ==!! what you want me to do? what you expect for?
i cant complete my work coz i really don't HOW to do..so i just ask at here...

well..is too sad u don't want to help..is ok :)

Re: C++ need help !

Posted: Mon Feb 14, 2011 1:03 am
by Nerrazzuri
lemonnutz wrote:ya..is my un-finish work..coz i don't know how to do ==!! what you want me to do? what you expect for?
i cant complete my work coz i really don't HOW to do..so i just ask at here...

well..is too sad u don't want to help..is ok :)
lol, you are not getting what I meant, just forget about it. Hope someone will help you soon.

Re: C++ need help !

Posted: Mon Feb 14, 2011 4:48 am
by SoullessSoul
LOL wad Nerrazzuri mean is show us your script ==''

Re: C++ need help !

Posted: Mon Feb 14, 2011 10:24 pm
by ShiunYean
Here's the code he sent to my pm on facebook:

Code: Select all

#include <iostream>
using namespace std;

void main()
{
int digit1=2,digit2=10,o;
char letter1=0,str2[11],len2;

for ( o=0; o < len2; o++ )
len2=strlen(str2);
cout<<"Please enter 6 to 10 character as password.Note that password must contain 2 digit,1 upper-case character,1 punctuation"<<endl;
cin.getline(str2,11);
if(str2[o]<digit1 && str2[o]>digit2 && str2[o]>len2){
cout<<"invalid"<<endl;
}else{
cout<<"valid"<<endl;
}
}

Re: C++ need help !

Posted: Tue Feb 15, 2011 12:05 am
by happy125
ShiunYean wrote:Here's the code he sent to my pm on facebook:

Code: Select all

#include <iostream>
using namespace std;

void main()
{
int digit1=2,digit2=10,o;
char letter1=0,str2[11],len2;

for ( o=0; o < len2; o++ )
len2=strlen(str2);
cout<<"Please enter 6 to 10 character as password.Note that password must contain 2 digit,1 upper-case character,1 punctuation"<<endl;
cin.getline(str2,11);
if(str2[o]<digit1 && str2[o]>digit2 && str2[o]>len2){
cout<<"invalid"<<endl;
}else{
cout<<"valid"<<endl;
}
}
his for loop no open bracket, never return 0, i recommend just using 2 and 10 in place of digit1/2. use variables such as 'i' or 'x' instead of o as its confusing.

Re: C++ need help !

Posted: Tue Feb 15, 2011 3:35 am
by Nerrazzuri
Some idea you can use.

Code: Select all

if (str[i] >= 0x30 && str[i] <= 0x39) continue; //0-9
if (str[i] >= 0x41 && str[i] <= 0x5A) continue; //A-Z
this is to check if the current str has the same keycode as in the condition loop. If it is the same, the continue then loop without looking to the code bottom.