-
unwanted blankness
Ok cross everything out, I got it to check the error, it checks it, if its <=1 or >3 then it goes back to wanting to know what the string is but if it is a correct answer it just goes to a blank line
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int X;
X=1;
while(X=1)
{
char option[3];
cout<<"Are you going to want to loop?\nYes or No: ";
cin>>option;
if(sizeof(option)<=1)
{
cout<<"Now why are you trying to enter something too tiny (pun intended) ;-)";
cin.get();
}
if(sizeof(option)>3)
{
cout<<"This isn't the time for buffer overflows yet";
cin.get();
}
else
{
if(strcmp(option,"Yes")==0||strcmp(option,"yes")==0)
{
char buffer[10];
cin>>buffer;
cout<<buffer;
cin.ignore();
cin.get();
}
if(strcmp(option,"No")==0||strcmp(option,"no")==0)
{
char buffer[10];
cin>>buffer;
cout<<buffer;
cin.ignore();
cin.get();
X=0;
}
}
}
cin.get();
return 0;
}
-
Code:
> if(strcmp(option,"Yes")==0||strcmp(option,"yes")==0)
> {
> char buffer[10];
> cin>>buffer;
cin >> buffer;
Can you rephrase your question? cin stands for console input. So this line waits for the user to enter something.
-
Yeah just saw that :-P, Thanks, stupid mistake ^.^
-
Ok but now for every error, its saying same size as yes, but not yes.... instead of me entering KK and it saying same size as no, but not no :(
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int X;
X=1;
while(X=1)
{
char option[3];
cout<<"Are you going to want to loop?\nYes or No: ";
cin>>option;
if(sizeof(option)<2)
{
cout<<"Now why are you trying to enter something too tiny (pun intended) ;-)";
}
if(sizeof(option)>3)
{
cout<<"This isn't the time for buffer overflows yet";
}
if(sizeof(option)==3&&!(strcmp(option,"yes")==0||strcmp(option,"Yes")==0))
{
cout<<"Tisk tisk, you tried to fool me by entering something the same size as yes, but not yes.\n";
}
if(sizeof(option)==2&&!(strcmp(option,"No")==0||strcmp(option,"no")==0))
{
cout<<"Tisk tisk, you tried to fool me by entering something the same size as no, but not no.\n";
}
else
{
if(strcmp(option,"Yes")==0||strcmp(option,"yes")==0)
{
char buffer[10];
cout<<"Ok, now try to overflow me\n";
cin>>buffer;
cout<<buffer;
cin.ignore();
cin.get();
}
if(strcmp(option,"No")==0||strcmp(option,"no")==0)
{
char buffer[10];
cout<<"Ok, now try to overflow me\n";
cin>>buffer;
cout<<buffer;
cin.ignore();
cin.get();
X=0;
}
}
}
return 0;
}
and if i type no it says the yes error but brings me to the overflow point
eDIT: Ahhh, should change to two first ||'s to &&'s
Brb
-
> while(X=1)
Remember = is assignment, and == is equality:
> char option[3];
Remember this can only hold two characters plus the string terminator. So if you want it to hold "yes", it needs to have 4 elements:
> if(sizeof(option)<2)
Instead of sizeof, use strlen() to find a char array's length:
Code:
if(strlen(option)<2)
To use strlen(), include <cstring>.
Why not use the string class instead. Then you can do stuff like:
Code:
string option;
.
.
if (option.length() < 2)
{
.
.
else
{
if (option == "Yes" || option == "yes")
{
-
How do we use the string class?
-
Try the tutorials.
Use = for assignment and + for concatention.
Code:
string firstname = "joe";
string lastname = "smith";
string fullname = firstname + " " + lastname;
-
THANK YOU!!! That made life so much easier but now it checks it, but loops anyway if you say no and it doesnt give the error messages
Code:
#include <iostream>
using namespace std;
int main()
{
int X;
X=1;
while(X=1)
{
string option;
cout<<"Are you going to want to loop?\nYes or No: ";
cin>>option;
int Y;
int Z;
Y=0;
while(Y>0)
{
Z=Y;
if(option.length()<3)
{
cout<<"Now why are you trying to enter something too tiny (pun intended) ;-)";
Y++;
}
if(option.length()>4)
{
cout<<"This isn't the time for buffer overflows yet";
Y++;
}
if(option.length()==4&&!(option=="yes"||option=="Yes"))
{
cout<<"Tisk tisk, you tried to fool me by entering something the same size as yes, but not yes.\n";
Y++;
}
if(option.length()==3&&!(option=="No")||option=="no")
{
cout<<"Tisk tisk, you tried to fool me by entering something the same size as no, but not no.\n";
Y++;
}
cout<<"That was your "<<Y<<" consecutive error, don't try to hack the non=hacking part";
if(Y=Z)
{
cout<<"Congrats, you had no error this time ;-)\n";
Y=0;
}
}
if (Y==0)//If there is no errors
{
if(option=="Yes"||option=="yes")
{
char buffer[10];
cout<<"Ok, now try to overflow me\n";
cin>>buffer;
cout<<buffer;
cin.ignore();
cin.get();
}
if(option=="No"||option=="no")
{
char buffer[10];
cout<<"Ok, now try to overflow me\n";
cin>>buffer;
cout<<buffer;
cin.ignore();
cin.get();
X=0;
}
}
}
return 0;
}
-
Click on the Submit button only once, even if the page is really slow to load (as it's doing lately).
Use == for comparison.
-
uuugh I want to tell it to display something if the text is as long as long but not "no"... maybe
Code:
if(option.length==2 && (option=!"No"||option=!"no"))
Edit:Got it, but longer than what I had hoped fr
Edit:Alright now I'm getting a F***ing "expected declaration before }" error message (on line 89(last line))
And i dont know what it wants
Code:
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
int V;
int W;
int X;
int Y;
int Z;
string option;
X=1;
while(X=1)
{
cout<<"Are you going to want to loop?\nYes or No: ";
cin>>option;
Y=0;
if(W==0)
{
W=1;
}
cout<<"\nThis is your "<<W<<" attempt\n";
if(option.length()<2)
{
cout<<"Now why are you trying to enter something too tiny (pun intended) ;-)\n";
Z++;
Y++;
W++;
}
if(option.length()>3)
{
cout<<"This isn't the time for buffer overflows yet\n";
Z++;
Y++;
W++;
V=1;
}
if(option.length()==3)
{
if(option=="Yes"||option=="yes")
{
char buffer[10];
if(V==1)
{
cout<<"Ok, Now is the time for overflowing me ^.^\n";
}
if(V==0)
{
cout<<"Ok, now overflow me\n";
}
cin>>buffer;
cout<<buffer;
}
else
{
cout<<"Tryin to trick me ey, thinkin your slick just putting the right amount in...noob\n";
W++;
}
}
}
if(option.length()==2)
{
if(option=="No"||option=="no")
{
char buffer[10];
if(V==1)
{
cout<<"Ok, Now is the time for overflowing me ^.^\n";
}
if(V==0)
{
cout<<"Ok, now overflow me\n";
}
cin>>buffer;
cout<<buffer;
X=0;
}
else
{
cout<<"Can't stand you, trying to trick me all the time...\n";
W++;
}
}
}
}