Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 07 Jul 2011
Offline Last Active Jul 15 2012 09:12 AM

#4959276 (C++ Beginner) I hate to post here, but... why won't my "if" stat...

Posted by on 15 July 2012 - 09:14 AM

Thanks... XD I knew I would feel dumb at the end of this one... always the little things.

Appreciate it. Sometimes it's just helpful to have someone else look at it.

#4959267 (C++ Beginner) I hate to post here, but... why won't my "if" stat...

Posted by on 15 July 2012 - 08:46 AM

I've worked with other languages in the past including basic and a lot of scripting languages, and I have worked a decent bit on C++ too. I haven't worked on C++ in quite a while now, and last night I was trying to refresh myself on the basics... so--and this is a little embarrassing--I wrote this small piece of code for a console program to send my girlfriend:

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
string username = "";

cout << "Hello \n";
cout << "What is your name? ";
getline (cin, username);
cout << "Your name is: " << username;
if (username == "Tiffany" || "tiffany" || "Tiffany McClure" || "tiffany McClure" || "Tiffany Mcclure" || "tiffany mcclue")
  cout << "Your name is Tiffany... \n The Creator has a message for you: \n I love you Cupcake";
  cout << "Your name is not Tiffany.";
return 0;

The problem is... it doesn't appear that the "if (username == "Tiffany" || "tiffany" || "Tiffany McClure" || "tiffany McClure" || "Tiffany Mcclure" || "tiffany mcclue")" statement evaluates correctly, as the program always displays the cout message in the "if" block, even if the if statement should be false.

I know these are beginner C++ concepts that have nothing to do with game development, but... this is like the only forum acct. I have for anything like this, and I hate to create another just to ask this somewhat stupid question.

I appreciate any help with this, I'm trying to pick up C++ again so that maybe I can do something useful with it.

EDIT: Oops. I haven't been on this site in a while. Forgot there was a "For Beginners" Section. This probably belongs there. Sorry about that.