| | |
No error But wrong Output. Why??
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2009
Posts: 27
Reputation:
Solved Threads: 2
I want to compare my password with the stored password but it don't compare correctly. WHY?
Please someone correct it.
Please someone correct it.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string.h> #include <conio.h> #include <cstdlib> using namespace std; int main() { string my = "programming "; string pass = ""; int s; int a; cout << "Enter password: "; do { // backspace not allowed a = _getch(); pass += char(a); cout << "*"; }while( a != 13 ); cout << endl << "Password is: " << pass << endl; cerr << " \n My: " << my << " \n "; //s = strlen(pass); //cerr << " Size: " << s; //if ( strcmp ( pass , my ) == 0 ) { if ( pass == my ) { cerr << "\n\n \t Password Comfirmed"; } else { cerr << "\n\n \t Not Confirmed"; } system("pause"); return 0; }
Last edited by Ancient Dragon; Jun 25th, 2009 at 7:10 am. Reason: add code tags
You're a spamming freak who continues to flout the rules about using code tags
http://www.daniweb.com/forums/thread199634.html
http://www.daniweb.com/forums/thread199634.html
•
•
Join Date: Jun 2009
Posts: 13
Reputation:
Solved Threads: 0
Try looking at your program again. Look at it closely when you type your password. I dont mean your typing it wrong, but when you press enter. Another star is added.. ex:
password: **** (hello)
password: hello ***** is wrong.. I'm sorry I cant explain it so well. You can't use enter just like you can't use backspace. I believe.
Sorry if that is wrong.
password: **** (hello)
password: hello ***** is wrong.. I'm sorry I cant explain it so well. You can't use enter just like you can't use backspace. I believe.
Sorry if that is wrong.
Last edited by valinux; Jun 25th, 2009 at 2:28 am.
"Learn It. Run it. Tinker with it."
This program is real rubbish, old style headers, conio, half of the code is commented out, system("pause") (don't use it), etc...
My recommendation is: migrate to standard C++ first, they really should make it a forum rule...
BTW, Does it really hurt you to use code tags:
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used
6) Even on the background of the box you actually typed your message in
(as already discovered by valinux):
If you still really want to fix your code, then you should add a check before adding the character to the variable, otherwise there will be an ENTER in the pass-string where you compare the real password to, always resulting in a Non Confirmed message, a simple check might look like this:
My recommendation is: migrate to standard C++ first, they really should make it a forum rule...
BTW, Does it really hurt you to use code tags:
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used
6) Even on the background of the box you actually typed your message in
(as already discovered by valinux):
If you still really want to fix your code, then you should add a check before adding the character to the variable, otherwise there will be an ENTER in the pass-string where you compare the real password to, always resulting in a Non Confirmed message, a simple check might look like this:
if( a != 13 ) pass += a;
Last edited by tux4life; Jun 25th, 2009 at 2:55 am.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
tux4life, I challenge you to write the same program with the same features and restrictions and show me how it's so much better than mirfan00's that he deserved all of that harassment. You're quick to mouth off, but can you back it up with your own perfection?
The only old style header is <string.h>, and even though it's officially deprecated, it's not going away any time soon because then compatibility with C would go out the window.
There's no way to replace typed characters with a star using standard code. To do that you have to use something that isn't portable, and conio is as good a choice as any for a toy program.
Only 3 lines out of over 40 are commented out. I didn't get good grades in grade school math classes, but I'm pretty sure 3 isn't even close to half of 40.
You forgot to say that <string> should be included because the code uses the standard C++ string class. And you forgot to say that '\r' is a portable replacement for 13. For all the complaining about old style headers, you forgot to say that the only code using them is commented out so both can be removed. I see you complaining about the same things over and over, and ignoring other things that are in the same league or worse. It kind of makes me think that you don't really know what you're talking about and just copy people who do.
•
•
•
•
This program is real rubbish, old style headers, conio, half of the code is commented out, system("pause")
There's no way to replace typed characters with a star using standard code. To do that you have to use something that isn't portable, and conio is as good a choice as any for a toy program.
Only 3 lines out of over 40 are commented out. I didn't get good grades in grade school math classes, but I'm pretty sure 3 isn't even close to half of 40.
You forgot to say that <string> should be included because the code uses the standard C++ string class. And you forgot to say that '\r' is a portable replacement for 13. For all the complaining about old style headers, you forgot to say that the only code using them is commented out so both can be removed. I see you complaining about the same things over and over, and ignoring other things that are in the same league or worse. It kind of makes me think that you don't really know what you're talking about and just copy people who do.
Last edited by Tom Gunn; Jun 25th, 2009 at 10:45 am.
-Tommy (For Great Justice!) Gunn
•
•
•
•
tux4life, I challenge you to write the same program with the same features and restrictions and show me how it's so much better than mirfan00's that he deserved all of that harassment. You're quick to mouth off, but can you back it up with your own perfection?
The only old style header is <string.h>, and even though it's officially deprecated, it's not going away any time soon because then compatibility with C would go out the window.
There's no way to replace typed characters with a star using standard code. To do that you have to use something that isn't portable, and conio is as good a choice as any for a toy program.
Only 3 lines out of over 40 are commented out. I didn't get good grades in grade school math classes, but I'm pretty sure 3 isn't even close to half of 40.
You forgot to say that <string> should be included because the code uses the standard C++ string class. And you forgot to say that '\r' is a portable replacement for 13. For all the complaining about old style headers, you forgot to say that the only code using them is commented out so both can be removed. I see you complaining about the same things over and over, and ignoring other things that are in the same league or worse. It kind of makes me think that you don't really know what you're talking about and just copy people who do.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
![]() |
Similar Threads
- Writing a program in java.Help!!! (Java)
- Array String (Java)
- output error in a simple C program for some values only (C)
- wrong output (C++)
- wrong output (C++)
- wrong output in c program (C++)
Other Threads in the C++ Forum
- Previous Thread: Can I return Vector from Virtual Function
- Next Thread: Pointers to functions?
Views: 376 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






