Valid and Invalid date (incorrect) HELP ASAP!

Assignment due in 2 days ASAP HELP

Please help me to find my errors!!

Also some date's don't come up or a valid date would be (example 32/12/16)
please help ....

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
#include <iostream> // cout, cin
#include <limits> // numeric_limits

using namespace std; // Avoid having to use std:: cout, std:: cin, etc

void drawMenu()
{
// The menu
cout << "******************************************************************" <<endl;
cout << "* choose an entry from 1 to 3.  *" <<endl;
cout << "* [1] validate modulus 11 number  *" <<endl;
cout << "* [2] validate data  *" <<endl;
cout << "* [3] quit  *" <<endl;
cout << "******************************************************************" <<endl;
}

int main()
{

//we can simply create a "game" loop for this appication

bool quit= false; // we haven't quitted yet
do
{
// the user choice
int choice;
// print the menu
drawMenu();
// Get the user choice
cin >> choice;


// error check again. include the fast that the number has to be 1-3
while (cin.fail() || choice <1 || choice > 3)
{
cout << endl << "choose a correct entry from 1 to 3 (with numbers)"
    << endl << endl;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n'); 
// draw the menu again
drawMenu();
cin >> choice;
}

//check the choice we have received 
switch (choice)
{
case1: // if the choice is 1

cout << endl << "Enter an ISNB number: " << endl << endl;
break;
   case 2:
  int day,dd,mm,yy,num;
 char ans;

 
while (true)
    {
        cout << "Enter Day: ";
        cin >> dd;
        cout << "Enter Month: ";
        cin >> mm;
        cout << "Enter Year: ";
        cin >> yy;

        if (dd > 0 && mm > 0 && yy > 0)
            break;


}

 // validation
 if (dd, mm, yy)
 int month [12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    if (yy % 4 == 0)
     
     if (mm <= 12 && dd <= "Month" [mm-1])
    {
        
        cout << "Date is valid\n";
    }
    else
        cout << "Error: Date is Invalid!\n";
    break;
   case 3:
quit = true;
break;
   default:
break;
        
        
    
        
   }
} while (!quit) ; // keep looping forever, until we quit

//say goodbye
cout << endl <<" shutting down. hope i'll see you soon!" << endl; 
return 0;
}

------------------------------------------------------------------------------







Last edited on
Please help me to find my errors!!

What errors?

I'm curious. What made you decide that the best way to get help for you problems was to not tell us what those problems are?
Divide and conquer.
Write many small functions, each one doing one small thing.
Take baby steps; write a function, test it, make sure it is working correctly before you proceed to the next function.

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
#include <iostream>
#include <limits>

void draw_menu()
{
    std::cout << "******************************************************************\n"
              << "* choose an entry from 1 to 3.  *\n"
              << "* [1] validate modulus 11 number  *\n"
              << "* [2] validate data  *\n"
              << "* [3] quit  *\n"
              << "******************************************************************\n";
}

int get_number() // read a valid number from stdin
{
    int number ;
    if( std::cin >> number ) return number ;

    // invalid input, inform the user, clear the input buffer and try again
    std::cout << "invalid number. please re-enter\n" ;
    std::cin.clear() ;
    std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
    return get_number() ;
}

int get_choice() // display the menu, return valid choice entered by the user
{
    draw_menu() ;

    const int choice = get_number() ;
    if( choice >= 1 && choice <= 3 ) return choice ; // valid choice

    return get_choice() ; // invalid choice, try again
}

bool valid_date( int dd, int mm, int yy )
{
    // *** TO DO: validate that dd/mm/yy forms a valid date
    //            if valid, return true

    return false ;
}

bool valid_modulo_11( int number )
{
    // *** TO DO: validate that number is a valid modulo 11 number
    //            if valid, return true

    return false ;
}

int main()
{
    bool quit = false ;

    do
    {
        const int choice = get_choice() ;

        switch(choice)
        {
            case 1:
            {
                std::cout << "enter modulo 11 number: " ;
                const int number = get_number() ;

                if( valid_modulo_11(number) ) std::cout << "yes, valid modulo 11 number\n" ;
                else std::cout << "that is not a valid modulo 11 number\n" ;

                break ;
            }

            case 2:
            {
                std::cout << "enter day: " ;
                const int dd = get_number() ;
                std::cout << "enter month: " ;
                const int mm = get_number() ;
                std::cout << "enter year: " ;
                const int yy = get_number() ;

                if( valid_date( dd, mm, yy ) ) std::cout << "valid date\n" ;
                else std::cout << "invalid date\n" ;

                break ;
            }

            case 3: quit = true ;
        }

    } while( !quit ) ;
}


Take it up from there.
Thanks the Invalid works but the Valid doesn't seem to work now :(
Last edited on
It is not intended to be a complete (or even a partially correct) program.
See the // *** TO DO: comments on lines 38-39, 46-47. They indicate what you need to do to complete it.

The approach I would suggest is what was indicated at the top.
Write the functions on your own (the snippet I posted may provide some guidance).
Take baby steps; write a function, test it, make sure it is working correctly before you proceed to the next function.

You have two days to do his; use the two days to refine it to the best of your ability.
Last edited on
closed account (48T7M4Gy)

@PleaseHM123


Two of your classmates are also working on this, so maybe you might like to work as a team since you've only got a short time and you all seem to be on the same track.

http://www.cplusplus.com/forum/general/192758/
http://www.cplusplus.com/forum/general/192757/

we have teamed up but we cant figure it out!
closed account (48T7M4Gy)
Ok then take JLBorges advice and just work on small steps. Just choose one small step and work on that together. Time is marching on.

Pick a small step and show us what your team has for code, test input, test output and how it differs from what the team expected.

Best stay with just one team thread too. Makes it easier to give feedback from your posts of small step stages.
Topic archived. No new replies allowed.