Simple date validating

I am in the middle of a program.
It is unfinished.
However i would like to validate the date.
I am stuck.
Please could you take 5 mins to look at this.

Here is the original program into which i want to add the date validation body to.
Please go ahead and run it.
I have completed option 1, and I am in the middle of completing option 2. Option 3 and 4 have not been attempted yet.

ORIGINAL PROGRAM
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <iostream.h>

#include <conio.h>

void WeeklySales(); //we make weeklysales a function here too

main()
	{
   	int number;

      do
      	{      //displays the menu
         	cout << "******Sales System******";
            cout << ("\n\n");
      		cout << "1. Display Company Logo.\n"; endl;
      		cout << "2. Input/Validate weekly sales data.\n";endl;
      		cout << "3. Calculate weekly sales.\n";endl;
      		cout << "4. Display reciept.\n";endl;
      		cout << "5. SHUT DOWN & LOG OFF.\n";endl;
				cout << "\nEnter number...\n";endl;
         	cin >> number;
            cout << ("\n\n");

      		switch (number)  //<--the expression is a variable (number) & controls the switch
            //the value of (number) is tested against a list of constants.
            //When a match is found, the statement sequence assosciated with that match is executed
               {
      				case 1:    //<-----  const = 1

            			cout << ("\n\tUU\tUU \tEEEEEEEE \tLL\t\t \SSSSSSS\n\tUU\tUU \tEE \t\tLL\t\tS\n\tUU\tUU \tEE \t\tLL\t\tS\n\tUU\tUU \tEEEEEEE \t\LL\t\t\ SSSSSS\n\tUU\tUU \tEE \t\tLL\t\t       S\n\tUU\tUU  \tEE  \t  \t\LL  \t\t       S \n\t UUUUUUUU   *\tEEEEEEEE  *\tLLLLLLL  *\tSSSSSSS   *\n\n\n\n\n");break;

            		case 2:   //<------const = 2. if match found, executes, then calls the weeklysales function below

            			cout << ("Weekly sales data\n\----------------- ");
                                WeeklySales();  //<-------------   function call here
                                break;

            		case 3:

            			cout << ("Calculate weekly sales "); break;

            		case 4:

            			cout << ("Display receipt "); break;

            		case 5:

            			cout << ("Goodbye, and thank you for using U.E.L.S. ");break;

                  //default statement sequence is executed if no matches are found
            		default:

            			cout << ("Enter a number from 1-5 only!");

         		}
      	} while (number !=5); //program will NOT stop looping till 5 is entered
      getch();
   }

void WeeklySales() //<--------weekly sales function not part of main() function
{                  //when function is completed, goes back to case 3:
//declare variables
	int salescode, bikeprice, modelcode, quantity, date;

   do
        //the instructions to enter the i.d. code will be repeated (do...while
        //loop) as long as the salescode is less than 1 or greater than 20.
   	{

      	cout << "\n\nPlease enter your identifiction code ";
         cin >> salescode;

         //the condition is tested
         if (salescode < 1 || salescode > 20)

         	{
            	cout << ("\nTHIS I.D. CODE IS NOT VALID. TRY AGAIN \n");
            }
      }
	//the instructions to enter the i.d. code will be repeated (do...while
   //loop) as long as the salescode is less than 1 or greater than 20.
   while (1 > salescode || salescode > 20);

   //another do...while loop
   do
   	{
      	cout << "\nPlease enter the bike price (one unit = 1 Euro) ";
      	cin >> bikeprice;

         if (bikeprice < 1 || bikeprice > 500)

         	{
            	cout << ("\nINVALID PRICE. Bike prices cannot be 0 or more than 500. TRY AGAIN \n");
            }
      }

   while (bikeprice < 1 || bikeprice > 500);

   //another do...while loop
   do
   	{
      	cout << "\nPlease enter the 3 digit model code ";
      	cin >> modelcode;

         if (modelcode < 0 || modelcode > 999)

         	{
            	cout << ("\nINVALID MODEL CODE. TRY AGAIN \n");
            }
      }

   while (modelcode < 0 || modelcode > 999);

   //another do...while loop
   do
   	{
         cout << ("\nPlease enter the quantity sold ");
      	cin >> quantity;

         if (quantity < 1 || quantity > 10)

         {
         	cout << ("\nINVALID QUANTITY. TRY A NUMBER FROM 1-10 \n");
         }
      }

   while (quantity < 1 || quantity > 10);



   //BELOW IS WHERE I WOULD HAVE TO PUT THE DATE VALIDATION PROGRAM IN ??? Would it be another do...while loop ?

      	cout << "\nPlease enter the date ";
      	cin >> date;

        	cout << ("\n\n\n\n\n\n");
}


as you can see, when an integer is entered for the date, the program will loop.

i tried to make another program with intentions of incorporating it into the original.
Would i put this next bit of code after line 131 ?
here it is: PROGRAM 2

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
39
#include <iostream.h>

#include <conio.h>

main()

{

 		int date;

      char yes, no;

      yes = 'y';

      no = 'n';

      do {

     				cout << "\nPlease enter the date. eg. 020410 is 02/04/10 ";

               cin >> date;

               cout << "\nIs the the correct date ? press y/n \n" << date;

               cin >> yes || no;  //<------ i wasnt sure if this was correct

               if (char == no )

               		{

                        cout << ("\nPlease re-enter the correct date \n");
                        cin >> date;
                     }

           } while (char == yes); //<-----here i would like it to go back to the menu screen

          getch();

          }


there are errors, what have i done wrong ? how would i incorporate this into the original ?

can you help ?
ok well you will have to tell us the errors and if your using vc++ 2008 you will need to change <conio.h> to <ctime> also look at the forums in the c language

ps nice code
Thanks MSkillet,
Well, i'm using borland 5.02 unfortunately (thats what we have to use).
not nothing as fancy as vc++ 2008.

the errors for PROGRAM 2are as follows.

Info :Compiling \\dl-stud1\Users\D35\u0944892\Desktop\PROGRAMASSIGNMENT\noname00.cpp
Error: noname00.cpp(27,27):Declaration terminated incorrectly
Error: noname00.cpp(35,13):If statement missing )
Error: noname00.cpp(35,28):Declaration terminated incorrectly
Error: noname00.cpp(35,34):While statement missing )
Error: noname00.cpp(39,1):do statement must have while
Error: noname00.cpp(44,1):Compound statement missing }
ok i took more time and read more of the code now you say that you want to add another program in one program if thats exactly what you are doing you will fail in the compiling of my knowledge your program # 2 would have to be something like

1
2
3
4
5
6
7
8
9
...// your #include(s)
int main () // needs to named something like int date () only because there allready is a int main() created i will tell you what i will copy this code into my computer and i will try to solve this program because it is real nice so if I find a solution i will tell you what to change

//base code

         getch();
         }
     return 0;
}


best of luck buddy
you can download vc++ 2008 for free onto your computer(s) just get the express edition and then after your 30-days give your email to microsoft and you get the full program for free.


i will look into what these errors are good luck bud
Last edited on
clio78 :
date should be devided in to three variables, Day,Month ,Year;
so you can operate on them if they change also char is a reserved word in c++ , you have to declare a variable with char first and then compare it whether it's 'y' or 'n', cin >> yes || no <-- don't work??? and you already have initalized them to 'y' and'n'.......:)
note c++ is case sensitve. ....:)

1
2
3
4
5
6
7
8
9
               if (char == no )

               		{

                             cout << ("\nPlease re-enter the correct date \n");
                        cin >> date;                        
                     }

           } while (char == yes); //<-----here i would like it to go back to the menu screen 





/me doesn't read

You'll need a function to do date validation.

The steps are these:
1. the year is always valid (unless you need it constrained to a specific range of years)
2. the month must be in 1..12 (or 0..11, as appropriate)
3. the number of days per month are prescribed for every month. You might want to use a simple lookup table. The only month of interest is February, whose number of days depend upon whether or not it is a leap year.

So, that's three tests and maybe one calculation.

Hope this helps.
@ Zinogg: thanks for catching what I have missed I can't believe that i skipped that part lol but yea it needs to be placed into 3 seperate variables

@ duoas: thats a good example keep up the great work

and @ OP I can't yet find a solution to this problem because the first program has errors so till i get that fixed we are sol ttul when i get it working on my system.

P.S. your includes are correct and wrong at the same time (according to vc++ 2008) change the #include <.....h> to #include <.........>
thanks
its ok I made that same mistake in my first code project
Topic archived. No new replies allowed.