(completed)Tiny C++ proggie ends for no reason

My tiny 150 line proggie ends and I can't stop it. I have the defensive coding and the coding to make it wait, yet to no avail. The proggie calculates the date you added into military time(just months with no years) while adjusting for leap years. The problem where it ends unexpectedly is only when the date isn't an actual date.

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
138
139
140
#include <string>
#include <iostream>
using namespace std; 

int main ( )
{
int day, month, year;
double daynum;

bool leapyear;

cout << "Enter month as a number" << endl;
cin >> month;
cout << "Enter day as a number" << endl;
cin >> day;
cout << "Enter year as a number" << endl;
cin >> year;

//Validating Year Value
if ( year < 2000 || year > 2099 )
{
cout <<  "Unacceptable Year Entered: " << year << endl;
cout <<   "Acceptable range For Year is 2000 to 2099 " << endl;
          exit (0);
}

//Determining Leap year
leapyear = false;
 if  ((year % 4) == 0)
{
          leapyear = true;
}

//Validating Month Value
if ( month < 1 || month > 12 )
{
           cout << "Invalid Month Entered: " << month << endl;
           exit (0);
}

//Validating Day Value
if ( ( day < 1 ) || ( day > 31 ) )
{         
cout << "Invalid Day Entered: " <<  day << endl;
cout << "Press ENTER to continue...";
cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
          exit (0);
}

//Validating Other Day Values

if (  ( month == 4 || month == 6 || month == 9 || month == 11)  && ( day > 30 ) )
{
          cout << "Mismatching Month/Day Values Entered. "  << endl;
          cout << "Month Value Entered: " << month << endl;
cout <<  "Day Value Entered: " << day << endl;
cout << "Press ENTER to continue...";
cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
          exit (0);
}
if ( (month == 2) && ( day > 29 ) && ( leapyear ) )
{
          cout << "Mismatching Month/Day Values Entered: " << endl;
          cout << "Month Value Entered: " << month << endl;
cout <<  "Day Value Entered: " << day << endl;
cout << "Press ENTER to continue...";
cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
          exit (0);
}

if ( (month == 2) && ( day > 28 ) && ( ! leapyear ) )
{
          cout << "Mismatching Month/Day Values Entered: " << endl;
          cout << "Month Value Entered: " << month << endl;
  cout <<  "Day Value Entered: " << day << endl;
  cout << "Press ENTER to continue...";
cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
          exit (0);
}

switch (month)
{
case 1:
daynum = day;
break;

case 2:
daynum = 31 + day;
break;

case 3:
daynum =31 + 28  + day;
break;

case 4:
daynum = 28 + 31 + day;
break;

case 5:
daynum =28 + 31 + 30 + day;
break;

case 6:
daynum =28 + 31 + 30 + 31 + day;
break;

case 7:
daynum =28 + 31 + 30 + 31 + 30 + day;
break;

case 8:
daynum =28 + 31 + 30 + 31 + 30 + 31 + day;
break;

case 9:
daynum = 28 + 31 + 30 + 31 + 30 + 31 + 31 + day;
break;

case 10:
daynum =28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + day;
break;

case 11:
daynum =28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + day;
break;

case 12:
daynum =28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + day;
break;

}

if (leapyear == true && month > 2)
  daynum = daynum +1;

cout << "Date: " <<day<< "\n" <<month<< "\n" <<year<< "\n" << daynum<<endl;
  cin.get();  cin.get();  cin.get();  cin.get();  cin.get();  cin.get();
  
exit (0);
}
Last edited on
Your
 
exit (0);

is closing your application, I suppose.
Just delete it and everything should be fine. It does not make sense anyway since it is the last command in the if-Statement and after that, the if-statement is finished anyway and the compiler will go to the next line of code.

regards
int main

Btw.: This date is not a military date-format. It simply is the Julianic Calender (or hwo it may be called in english).
A military date has the format of:
two digits for the day
two digits for the hour
two digits for the minutes
one letter for the timezone
a space
three letters for the month
a space
four digits for the year

Example: today, 1:15 p.m. in Germany would be:
011315B Jul 2008 during summertime, all time-zones shift one up.
which equals:
011115Z Jul 2008 using Zulu as a reference
which equals:
011515D Jul 2008 Using Moscow-time as a reference

and so on.
Last edited on
thank you very much. I will tell my teacher about the Junianic Calendar and deleting the "exit (0);" worked like a charm!
Last edited on
Topic archived. No new replies allowed.