String Code??

I am trying to create a code where when day or night is entered, the program will tell you if you are working shift one or shift 2. Any help would be appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  #include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
	string day, night;
	string shift;
	bool return_value = false;

cout << " Please enter whether your shift is day or night" << endl;
	cin >> shift;

	if (shift == day)
	{
		return_value = true;
		std::cout << "shift 1" << endl;
	}

	if (shift == night)
	{
		
	return_value = true;
	std::cout << "shift 2" << endl;
	}
	cin >> shift;
	cout << return_value << endl;

	return return_value;
	return 0;
Strings are initialized to have no characters (they are "empty" strings).

Try running your program and just pressing Enter. It will think you are on shift 1, because day has a value of "".

1
2
string day = "day";
string night = "night";

Try that and run your program again.

Keep in mind that the user may also input things like "d" and "Day". If this is a simple assignment, don't worry about that. Otherwise you might want to spend some time checking against user randomness.

Also, what if the user enters "neither" or "golden brown" or " HELP!"?

Good luck!

Thank you so much for your help! It's all squared away!
Topic archived. No new replies allowed.