Why is my loop / if statement not working?

When the user inputs the month January or February, it will ignore the maxMinutes I set for those month & say the minutes cannot exceed 43200 which should only apply to the June, April, Sept, Nov. What am I doing wrong??? Thanks

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
  //Minutes per Month
	double maxMinutes = 0.00;
	if (month == "January" || "March" || "May" || "July" || "August" || "October" || "December");
	{
		maxMinutes = 44640;
	}

	if (month == "February");
	{
		maxMinutes = 40320;
	}

	if (month == "April" || "June" || "September" || "November");
	{
		maxMinutes = 43200;
	}


	//Asks the user number of minutes used
	cout << "How many minutes were used? ";
	cin >> minutes;
	while (minutes < 0 || minutes > maxMinutes)
	{
		cout << "Minutes cannot exceed " << maxMinutes << "." << " Please enter the correct amount of minutes." << endl;
		cin >> minutes;
	}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
if (month == "January" || "March" || "May" || "July" || "August" || "October" || "December") // <==
{
	maxMinutes = 44640;
}

if (month == "February") // <==
{
	maxMinutes = 40320;
}

if (month == "April" || "June" || "September" || "November") // <==
{
	maxMinutes = 43200;
}


No semi-colon (;) after the if-statements.

1
2
3
4
if (month == "January" || month == "March" || month == "May" || month == "July" || month == "August" || month == "October" || month == "December") // <==
{
	maxMinutes = 44640;
}


You need to compare month to each value, otherwise it will render your if-statement unusable because it always returns true.
Last edited on
Thanks for replying.. I removed the semi-colon, but it didn't fix it, if I enter "January" it will say maxMinutes = 43200.
1
2
3
4
if (month == "January" || month == "March" || month == "May" || month == "July" || month == "August" || month == "October" || month == "December") // <==
{
	maxMinutes = 44640;
}


You did not fix it because you didn't listen to the half-bottom part of my post.

You need to compare month to each value, otherwise it will render your if-statement unusable because it always returns true.

So instead of :

if (month == "April" || "June" || "September" || "November")

You need to compare month to each value like this :

if (month == "April" || month == "June" || month == "September" || month == "November")
Last edited on
oh DUH. Thank you so much for pointing that out!
Topic archived. No new replies allowed.