I need some help with a program I'm working on, I have to calculate the cost of a long distance phone call based on the day, time and length of the call. This is what I have so far. I need to figure out how to test what day they are entering and the day is written like this - Mo, Tu, We, Th etc.

#include <iostream.h>

using namespace std;

int main()
{
	char M[256], day[256];

	cout << "Enter the day you have made your call (enter as Mo, Tu, We, Th, Fr, Sa or Su) "
		 << " the time (in 24 hour notation) the call started and the length of the call." << endl;
	cin.getline (day,256);
	cout << day;

	if (day == "Mo")
	{
		cout << endl << "Monday" << endl;
	}
	else
	cout << "fail";

	system("pause");
	return 0;
}

So right now it fails because it can't check whether the day is Monday.

Better use std::string class:

#include <iostream>
#include <string>
using namespace std;
...
string day;
...
getline(cin,day);
if (day == "Mo") ...

To compare C-style strings use strcmp function from <cstring> header:

if (strcmp(day,"Mo") == 0) ...

Now in day == "Mo" you compare pointers (not contents). Of course, you will never get true...

Thanks, seems to work well now

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.