46 Replies - 2978 Views - Last Post: 06 October 2012 - 09:37 AM
#31
Re: Password C++
Posted 01 October 2012 - 07:55 AM
Source : I have to endure TC++ every single day at school!
#32
Re: Password C++
Posted 01 October 2012 - 07:00 PM
#include <iostream> #include <string> using namespace std; //put that at the top, you shouldnt need anything else
#33
Re: Password C++
Posted 01 October 2012 - 07:00 PM
#include <iostream> #include <string> using namespace std; //put that at the top, you shouldnt need anything else
#34
Re: Password C++
Posted 01 October 2012 - 07:42 PM
#35
Re: Password C++
Posted 01 October 2012 - 08:38 PM
#36
Re: Password C++
Posted 01 October 2012 - 09:35 PM
#37
Re: Password C++
Posted 02 October 2012 - 05:51 AM
snoopy11, on 30 September 2012 - 11:30 PM, said:
This is a bit convuluted but it should work in Turbo for your password routine
int main()
{
char text[5],password[5];
sprintf(text, "user");
cout<<"Enter Password: ";
cin>>password;
int length1 =strlen(text);
int length2 =strlen(password);
if(strstr(password,text)&& (length1==length2))
cout<<"Correct!\n";
else
cout << "Incorrect\n";
return 0;
}
Also this is October so no help there.....
Also asking where you can stick your code is far too tempting
Only Kidding
Snoopy
Thanks i will study this.
aresh, on 01 October 2012 - 12:49 AM, said:
Untalented, it would be better if you read up something about functions first, since you are trying to define your functions inside main(), which is wrong. So, read up the links somebody here posted, and then tackle this problem again.
Thanks i will backread.
While inside the class im thinking about the while loop,
#include<iostream.h>
#include<string.h>
int function prototype;
int function prototype;
int function prototype;
int main()
{
//int or char or what should i use for my program to accept both number and letter. maybe string
cout<<"Enter Password: ";
cin>>password;
while(password!=password123){
cout<<"Incorrect";
}
else{
code code code // will my codes execute on this part?
}
return 0;
}
Is this the right sequence?
Thanks for giving me ideas. will be back on Sat. Thanks
#38
Re: Password C++
Posted 02 October 2012 - 09:24 AM
I think that you will discover that compiler won't let you have an else clause for while statement.
#39
Re: Password C++
Posted 06 October 2012 - 04:41 AM
[
#include<iostream.h>
#include<string.h>
#include<conio.h>
int testprog();
int main()
{
clrscr();
char password[10];
cout<<"Enter Password: ";
cin>>password;
if(password=="test"){
testprog();
}
else{
cout<<"Error";
}
cin.ignore();
cin.get();
return 0;
}
int testprog(){
int n1,n2,sum;
cout<<"Enter First number: ";
cin>>n1;
cout<<"Enter second number: ";
cin>>n2;
sum=n1+n2;
cout<<"The sum is "<<sum;
cin.ignore();
cin.get();
return 0;
}
Dev C++ [Working]
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
int main(){
string pass ="";
char ch;
cout << "Enter pass\n";
ch = _getch();
while(ch != 13){
pass.push_back(ch);
cout << '*';
ch = _getch();
}
if(pass == "test"){
cout << "\n Correct! \n";
}else{
cout << "\n Wrong\n";
}
cin.get();
return 0;
}
I tried converting to Old Turbo C++
Error
Line 6: Undefined symbol string
Line 6: statement missing ;
Line 10: function _getch()should have a prototype
Line 12: undefined symbol pass
#include <iostream.h>
#include <string.h>
#include <conio.h>
int main(){
string pass ="";
char ch;
cout << "Enter pass\n";
ch = _getch();
while(ch != 13){
pass.push_back(ch);
cout << '*';
ch = _getch();
}
if(pass == "test"){
cout << "\n Correct! \n";
}else{
cout << "\n Wrong\n";
}
cin.get();
return 0;
}
This post has been edited by Untalented: 06 October 2012 - 05:02 AM
#40
Re: Password C++
Posted 06 October 2012 - 07:25 AM
And in Turbo-C it is getch() not _getch().
Jim
This post has been edited by jimblumberg: 06 October 2012 - 07:26 AM
#41
Re: Password C++
Posted 06 October 2012 - 07:55 AM
This is my new code and finally it is working. the problem is i can only make it work using numbers as my password. As for characters i will try to use strcmp()
// is strcmp the most ideal to make the password program in turbo c++ (old one)?
#include<iostream.>
#include<string>
#include<conio.h>
#include <stdlib.h>
using namespace std;
int testprog();
int main()
{
system("cls");
int password;
cout<<"Enter Password: ";
cin>>password;
if(password==321){
testprog();
}
else{
cout<<"Error";
}
cin.ignore();
cin.get();
return 0;
}
int testprog(){
int n1,n2,sum;
cout<<"Enter First number: ";
cin>>n1;
cout<<"Enter second number: ";
cin>>n2;
sum=n1+n2;
cout<<"The sum is "<<sum;
cin.ignore();
cin.get();
return 0;
}
[Turbo C++]
3 Errors
Line 6: Undefined symbol string
Line 6: statement missing ;
Line 12: undefined symbol pass
#include <iostream.h>
#include <string.h>
#include <conio.h>
int main(){
string pass ="";
char ch;
cout << "Enter pass\n";
ch = getch();
while(ch != 13){
pass.push_back(ch);
cout << '*';
ch = getch();
}
if(pass == "test"){
cout << "\n Correct! \n";
}else{
cout << "\n Wrong\n";
}
cin.get();
return 0;
}
Strcmp
Im not sure if i am right, the strcmp will compare password and pw right? and if it is equal it should be zero..
It is still skipping my first if condition. im not sure if i can put strcmp and add == 0 there. but obviously im wrong
#include<iostream.>
#include<string>
#include<conio.h>
#include <stdlib.h>
#include<cstring>
using namespace std;
int testprog();
int main()
{
system("cls");
char password[20];
char pw[20]="untalented";
cout<<"Enter Password: ";
//gets(password);
cin>>password;
strcmp(password,pw);
if(strcmp==0){
testprog();
}
else{
cout<<"Error";
}
cin.ignore();
cin.get();
return 0;
}
int testprog(){
int n1,n2,sum;
cout<<"Enter First number: ";
cin>>n1;
cout<<"Enter second number: ";
cin>>n2;
sum=n1+n2;
cout<<"The sum is "<<sum;
cin.ignore();
cin.get();
return 0;
}
This post has been edited by Untalented: 06 October 2012 - 08:21 AM
#42
Re: Password C++
Posted 06 October 2012 - 08:25 AM
if (strcmp(password, pw) == 0) {
testprog();
}
#43
Re: Password C++
Posted 06 October 2012 - 08:29 AM
I think someone has already mentioned it, it just doesn't work with TC++. So, use char[] to hold strings.
#45
Re: Password C++
Posted 06 October 2012 - 09:12 AM
I will just need to mask the password by asterisk.
Im refering to this one.
Im getting error on line 12 structure required on left side of . or .*
What is the right syntax for that?
#include <iostream.h>
#include <string.h>
#include <conio.h>
int main(){
char pass[20];
char ch;
cout << "Enter pass\n";
ch = getch();
while(ch != 13){
pass.push_back(ch);
cout << '*';
ch = getch();
}
if(pass == "test"){
cout << "\n Correct! \n";
}else{
cout << "\n Wrong\n";
}
cin.get();
return 0;
}
|
|

New Topic/Question
Reply




MultiQuote






|