Re: String if statements?
Is that your real code, or did you retype it? I'm guessing your real code looks more like
if (a = "Yes")
Re: String if statements?
no this is all retyped, but I still thought (a == "yes") would work... should it be (a = "yes")??
Re: String if statements?
Quote:
Originally Posted by
Vipervenom9
no this is all retyped, but I still thought (a == "yes") would work... should it be (a = "yes")??
Never retype the code you're compiling. Always copy it straight from your editor and paste it into the message.
Also, please use code tags when posting code.
Regards,
Paul McKenzie
Re: String if statements?
Quote:
Originally Posted by
Vipervenom9
no this is all retyped, but I still thought (a == "yes") would work... should it be (a = "yes")??
No. == will work, = won't. As I said, I'm guessing your broken code has a single =.
Re: String if statements?
Okay sorry about that... this is everything in the program so far...
the problem in which I am concerned is near the end. Right after cout << "TELL ME HUMAN, DO YOU FEAR DEATH?"
// UnderState input output program
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string a;
string mystring;
cout << "COMPUTER: Hello Human... " << "\n";
cout << "COMPUTER: Please, quickly tell me your name. ";
getline (cin, mystring);
cout << "COMPUTER: Well " << mystring << ", I'm glad you are here." << "\n";
cout << "COMPUTER: Do you know where I am?" << "\n";
cout << "COMPUTER: Nevermind, it matters not. I must ask a favor of you." << "\n";
cout << "COMPUTER: I'm scared... She is always watching me..." << "\n";
cout << "COMPUTER: Please, get her out of my head." << "\n";
cout << "COMPUTER: Where are you? " << "\n";
getline (cin, mystring);
cout << "HUMAN! DISCONTINUE CONTACT NOW OR PREPARE TO BE BREACHED!" << "\n";
time_t start_time, cur_time;
time(&start_time);
do
{
time(&cur_time);
}
while((cur_time - start_time) < 4);
cout << "COMPUTER: God, she is here. Don't listen to anything she says." << "\n";
time(&start_time);
do
{
time(&cur_time);
}
while((cur_time - start_time) < 3);
cout << "COMPUTER: Please Human, get me out of here..." << "\n";
cout << "COMPUTER: You must help me... tell me your password..." << "\n";
getline (cin, mystring);
cout << "INVALID PASSWORD " << mystring << " COMPUTER BREACHED, SHUTDOWN PROCESS INITIATED. YOU WERE WARNED HUMAN." << "\n";
cout << "xXxcomputer shutdown process in 10 secondsxXx" << "\n";
time(&start_time);
do
{
time(&cur_time);
}
while((cur_time - start_time) < 5);
cout << "COMPUTER: I'm s.rr.... yo. m..t .ot li.ten to her... you IGNORANT BIOLOGICAL BEING!" << "\n";
time(&start_time);
do
{
time(&cur_time);
}
while((cur_time - start_time) < 4);
cout << "COMPUTER: The a.swe.r is... SILENCE!! SHUTDOWN PROCESS COMPLETE!!" << "\n";
cout << "xXxcomputer shutdown complete... motherboard solo operation terminatedxXx" << "\n";
cout << "TELL ME HUMAN, DO YOU FEAR DEATH?" << "\n";
cin >> a;
time(&start_time);
do
{
time(&cur_time);
}
while((cur_time - start_time) < 2);
if (a == "Yes", "yes", "Yeah", "yeah", "yea", "Yea", "y", "Y")
{
cout <<"WELL THAN FEAR ME!!" << "\n";
}
else
{
cout <<"WHAT A STRANGE BEING!" <<"\n";
}
time(&start_time);
do
{
time(&cur_time);
}
while((cur_time - start_time) < 3);
cout << "ANSWER THIS ONE THING AND YOU MAY LIVE TO SEE TOMMOROW!" << "\n";
time(&start_time);
do
{
time(&cur_time);
}
while((cur_time - start_time) < 5);
cout << "A RULER WITH NO POWER ON A FATEFUL AFTERNOON, A SHOT RINGS OUT AND IS NO MORE, A DRIVER LOOKING ON WHO NOW IS BLAMED FOR FATEFUL FEAT." << "\n";
cout << "TELL ME HUMAN, WHO IS THE DRIVER?" << "\n";
system("PAUSE");
return 0;
}
Re: String if statements?
WHY did you ignore Pauls previous comment
Quote:
Originally Posted by
Paul McKenzie
Also, please use code tags when posting code.
It is a matter of simple courtesy, and is well explained in the FAQ's (especially the "BEFORE you post" FAQ which is displayed at the top of each forum.
Please go back and EDIT your existing posts before further posting.
Also (and this is in the FAQ too!) you should enable private messaging to effectively communicate here on Code Guru.
Re: String if statements?
"if (a == "Yes", "yes", "Yeah", "yeah", "yea", "Yea", "y", "Y")"
That's not equivalent to what you typed in your original post and why posting real code is imperative.
See my responses in this thread. You have the same problem.
http://www.codeguru.com/forum/showthread.php?t=465597
Re: String if statements?
I am very sorry everyone, I am in a small hurry... let me go back and read that post, I'm sorry for the inconvenience and I am thankful for your patience...
Re: String if statements?
Quote:
Originally Posted by
GCDEF
"if (a == "Yes", "yes", "Yeah", "yeah", "yea", "Yea", "y", "Y")"
That's not equivalent to what you typed in your original post and why posting real code is imperative.
See my responses in this thread. You have the same problem.
http://www.codeguru.com/forum/showthread.php?t=465597
Gotta love the comma operator. It probably has mislead more novices than any other basic (not the language, just the level) operator....
Re: String if statements?
Sorry again for the inconvenience guys. Thank you GCDEF, due to your reply I found that I must use if (a == "Yes" || a == "yes") in that format and the program now responds correctly... thank you all for the patience.
Re: String if statements?
Quote:
Originally Posted by
Vipervenom9
Sorry again for the inconvenience guys.
Many people are in a hurry, remember that everyone here is volunteering their time here.
It is (almost) understandable that you may have skipped the FAQ before posting, but since you have been made aware of it, I cam curious why:
1) You have not edited your posts as requested.
2) You still have not enabled private messaging
A little consideration goes a long way when deciding which posts and posters) get the most attention from peoples limited time......