My code won't work correctly
Page 1 of 1 • Share
My code won't work correctly
At the end it doesn't work correctly.
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
//including valueable things ^
int main()
{
string pass;
string user;
int fails = 0;
char YN;
int pen;
string inpass;
string hint;
int done = 0;
int donee = false;
//Variables ^
cout << "If someone geths your password how long do you want them to wait?\n";
cout << "(1 secong = 1000) Seconds: ";
cin >> pen;
//Penilization ^
cout << "Make a username: ";
cin >> user;
Sleep(700);
while (done == 0){
cout << "Make a password: ";
cin >> pass;
Sleep(700);
Sleep(700);
cout << "Sure you want your password to be " << pass << "?\n YN: ";
cin >> YN;
if (YN == 'N'){
done = 0;
cout << "Redo! -->\n";
}
else if (YN == 'Y'){
done = 1;
cout << "Great!\n";
}
else{
cout << "What?\n";
done = 0;
}
}
//creation ^
cout << "Make a hint: ";
cin >> hint;
//The hint ^
Sleep(700);
while (donee == false){
cout << user << endl;
cout << "Password: ";
cin >> inpass;
if (inpass == pass){
cout << "Logging in\n";
donee = true;
}
else{
fails++;
}
if (fails == 3)
hint;
else if (fails == 6)
cout << "Penilizing\n";
Sleep('pen');
}
//Login ^
return 0;
}
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
//including valueable things ^
int main()
{
string pass;
string user;
int fails = 0;
char YN;
int pen;
string inpass;
string hint;
int done = 0;
int donee = false;
//Variables ^
cout << "If someone geths your password how long do you want them to wait?\n";
cout << "(1 secong = 1000) Seconds: ";
cin >> pen;
//Penilization ^
cout << "Make a username: ";
cin >> user;
Sleep(700);
while (done == 0){
cout << "Make a password: ";
cin >> pass;
Sleep(700);
Sleep(700);
cout << "Sure you want your password to be " << pass << "?\n YN: ";
cin >> YN;
if (YN == 'N'){
done = 0;
cout << "Redo! -->\n";
}
else if (YN == 'Y'){
done = 1;
cout << "Great!\n";
}
else{
cout << "What?\n";
done = 0;
}
}
//creation ^
cout << "Make a hint: ";
cin >> hint;
//The hint ^
Sleep(700);
while (donee == false){
cout << user << endl;
cout << "Password: ";
cin >> inpass;
if (inpass == pass){
cout << "Logging in\n";
donee = true;
}
else{
fails++;
}
if (fails == 3)
hint;
else if (fails == 6)
cout << "Penilizing\n";
Sleep('pen');
}
//Login ^
return 0;
}
CPSNAP
Re: My code won't work correctly
I would like to help you, but I must to go to school now so maybe later ;D
lolslayer
Re: My code won't work correctly
Well I was able to find the issues, but in the future if you could give some more information about your code such as: language used, and possible errors that were produced by the compiler then it would help those who are looking for bugs. It might not hurt to add more commenting as well as proper spacing between segments.
The first thing that I found was a discrepancy between your variable donee as it was assigned and as it was used. For example you assigned donee as an int when it should have been a boolean so it should have looked like: "bool donee = false;" I would also recommend using boolean for your "done" variable as well.
The next thing was the comparison of the inpass and pass strings. When you use "==" with strings you are only comparing the memory addresses and not the actual strings, so to compare the strings you will use a comparison function and that comparison would look like:
"if( inpass.compare(pass) ==0)..." (When comparison function returns 0 the strings are the same)
Here is the corrected code, I took the liberty of cleaning things up if you don't mind.
The first thing that I found was a discrepancy between your variable donee as it was assigned and as it was used. For example you assigned donee as an int when it should have been a boolean so it should have looked like: "bool donee = false;" I would also recommend using boolean for your "done" variable as well.
The next thing was the comparison of the inpass and pass strings. When you use "==" with strings you are only comparing the memory addresses and not the actual strings, so to compare the strings you will use a comparison function and that comparison would look like:
"if( inpass.compare(pass) ==0)..." (When comparison function returns 0 the strings are the same)
Here is the corrected code, I took the liberty of cleaning things up if you don't mind.
- Code:
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
//including valueable things ^
int main()
{
string pass;
string user;
int fails = 0;
char YN;
int pen;
string inpass;
string hint;
bool done = false;
bool donee = false;
//Variables ^
cout << "If someone gets your password how long do you want them to wait?\n";
cout << "(1 second = 1000) Seconds: ";
cin >> pen;
//Penilization ^
cout << "Make a username: ";
cin >> user;
Sleep(700);
while (done == false){
cout << "Make a password: ";
cin >> pass;
Sleep(1400);
cout << "Sure you want your password to be " << pass << "?\n YN: ";
cin >> YN;
if (YN == 'N'){
done = false;
cout << "Redo! -->\n";
}
else if (YN == 'Y'){
done = true;
cout << "Great!\n";
}
else{
cout << "What?\n";
done = false;
}
}
//creation ^
cout << "Make a hint: ";
cin >> hint;
//The hint ^
Sleep(700);
while (donee == false){
cout << user << endl;
cout << "Password: ";
cin >> inpass;
if ( inpass.compare( pass) == 0){
cout << "Logging in\n";
donee = true;
}
else{
fails++;
}
if (fails == 3){
cout << "Hint: " << hint << "\n";
} else if (fails == 6){
cout << "Penilizing \n";
Sleep( pen );
fails = 0;
}
}
//Login ^
return 0;
}
bob1ngton
Re: My code won't work correctly
If I did something wrong please correct me otherwise I'm not sure what to say. I am just correcting out of information that I have learned over the past few semesters at college.
bob1ngton
Re: My code won't work correctly
I mean, like, "bro, you loco"bob1ngton wrote:If I did something wrong please correct me otherwise I'm not sure what to say. I am just correcting out of information that I have learned over the past few semesters at college.
HatchetHaro
Re: My code won't work correctly
Show me more magic twicks plzbob1ngton wrote:If I did something wrong please correct me otherwise I'm not sure what to say. I am just correcting out of information that I have learned over the past few semesters at college.
DatGuyYouKnow
Re: My code won't work correctly
why is everybody like holy shit here xD
I mean, it's very cool and I can't do better, but a normal student in the last grade can do this xDDD
I mean, it's very cool and I can't do better, but a normal student in the last grade can do this xDDD
lolslayer
Re: My code won't work correctly
I totally agree, what I did to the code was just basic formatting and logic. You don't really start to get into coding until you deal with object oriented design in addition to advanced data structures.
bob1ngton
Re: My code won't work correctly
I know, I could probably do the same thing but 1. I don't know the language, and 2. I'm lazy.
HatchetHaro
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|