string if function?

how to compare string input?

Page 1 of 1

2 Replies - 1170 Views - Last Post: 16 June 2009 - 08:30 PM Rate Topic: -----

#1 AGRAC393   User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 248
  • Joined: 13-May 09

string if function?

Posted 16 June 2009 - 08:19 PM

Hello,
This post is kind of embarassing to me, but maybe it's the late night programming... I'm trying to compare the input placed in a string to a set thing... You will see. I feel like I'm losing progress :(
	string event, none;
	string place;
	int month, day, year, hour, min, y, n;

	system("CLS");
	cout << "								 Event Scheduler\n\n";
	cout << "Enter an event that you would like to be reminded of!\n";
	cout << "\n";
	cout << "If you have no events to be reminded of, enter none or, press the \nX button in the top right corner\n\n";
	cout << "If you have no events to be reminded of, enter none or, press the \nX button in the top right corner\n\n";
	cin >> event;

if (event == none)
{
return 0;
}

else
{
	
	system("CLS");
	cout << "Today's date is: " << _strdate( dateStr);
	cout << "\nEnter month of the event\n";
	cin >> month;
	cout << "\nEnter day of the event\n";
	cin >> day;
	cout << "\nEnter the year of the event\n";
	cin >> year;


With this configuration, it compiles and will accept input but it will go through the return 0; and go to the today's date section. What I would like to do is have the user enter none, and then the program closes. The rest of my code works, I just cut it out to save time. Once again, I'm sure this is something easy, but it's late and I want to get this done before I go to bed ;)

Is This A Good Question/Topic? 0
  • +

Replies To: string if function?

#2 apw5020   User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 666
  • Joined: 26-March 09

Re: string if function?

Posted 16 June 2009 - 08:28 PM

if (event == none)


should be
if(event == "none")



You only want to see if the word stored in 'event' is "none". The way you currently have it compares the string variables 'event' and 'none', and since you never store anything in 'none', the expression will always evaluate to false.

This post has been edited by apw5020: 16 June 2009 - 08:34 PM

Was This Post Helpful? 1
  • +
  • -

#3 AGRAC393   User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 248
  • Joined: 13-May 09

Re: string if function?

Posted 16 June 2009 - 08:30 PM

View Postapw5020, on 16 Jun, 2009 - 07:28 PM, said:

if (event == none)


should be
if(event == "none")



apw, you always have my back man! Thank you sooooo much! Now I can sleep! Like I said, an easy error caused by sleep deprivation

This post has been edited by AGRAC393: 16 June 2009 - 08:33 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1