Sentinel Help

I'm trying to have the program exit the loop when the sentinel is entered and I'm pretty sure it has something to do with reading m while inside the while loop. Please help! Pseudocode your responses, if possible. I just need a kick in the right direction.

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
33
34
35
36
37
38
#include <iostream>
#include <string>
using namespace std;

const int SENTINEL = -1;

void errorCheck (int, int, int, int&, int&, int&);
void year (int, int&);
void month (int, int, int&);
void day (int, int, int, int&);
void weekday (int, int, int, int);

int main ()
{//1
	int m=0, d=0, y, total=0;
	int errorm=0, errord=0, errory=0;

	while (m != SENTINEL)
	{//20
		cout << "Enter random 2-digit month and day and a 4-digit year." << endl;
		cout << "For example: 10 05 1989, then press enter." << endl;
		cin >> m >> d >> y;
		cout << endl;

		errorCheck (m, d, y, errorm, errord, errory);

		if (!errorm && !errord && !errory)
		{//3
			year (y, total);
			month (m, y, total);
			day (d, m, y, total);
			weekday (m, d, y, total);
		}//3
	}//2

	system("pause");
	return 0;
}//1 
Last edited on
I think if you wanted it to error check after each input then you would have to change the cin's

maybe have it cin month then error check, cin day then error check, then cin year and error check.

Right now it's taking all 3 cin's then doing the error check.


I'm a noob here, but what is it suppose to do when it encounters an error?

It looks to me if you enter -1 for m it will run through the program once then exit. Nothing will be displayed because it wouldn't match any of the cases?
Last edited on
Topic archived. No new replies allowed.