No errors in DevC++ but tons in MS Visual C++

5 years ago I tried my hand at C++. I only wrote one little program (Date Calculator) and I remember compiling it in DevC++.
Today I found a draft of the code so downloaded MS Visual C++ Express 2010 and pasted it in. Clicked on "Build Solution" (which I assume means compile?) only to find it throws up loads errors and stops compiling.
So I downloaded DevC++, pasted it in and clicked Compile. It compiled with no errors.
What makes MS Visual C++ hate my code so much?

This is what MS Visual C++ says.....
1
2
3
4
5
6
7
1>  DayfromDate.cpp
1>DayfromDate.cpp(7): warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1>          Add directive to 'StdAfx.h' or rebuild precompiled header
1>DayfromDate.cpp(8): warning C4627: '#include <string>': skipped when looking for precompiled header use
1>          Add directive to 'StdAfx.h' or rebuild precompiled header
1>DayfromDate.cpp(308): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

So I added #include <StdAfx.h> and now it returns this.....

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
1>  DayfromDate.cpp
1>DayfromDate.cpp(7): warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1>          Add directive to 'StdAfx.h' or rebuild precompiled header
1>DayfromDate.cpp(8): warning C4627: '#include <string>': skipped when looking for precompiled header use
1>          Add directive to 'StdAfx.h' or rebuild precompiled header
1>DayfromDate.cpp(17): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(18): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(19): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(20): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(21): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(23): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(24): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(25): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(26): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(27): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(28): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(30): error C2065: 'string' : undeclared identifier
1>DayfromDate.cpp(30): error C2146: syntax error : missing ';' before identifier 'start'
1>DayfromDate.cpp(30): error C2065: 'start' : undeclared identifier
1>DayfromDate.cpp(31): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(32): error C2065: 'cin' : undeclared identifier
1>DayfromDate.cpp(32): error C2065: 'start' : undeclared identifier
1>DayfromDate.cpp(34): error C2065: 'start' : undeclared identifier
1>DayfromDate.cpp(34): error C2065: 'start' : undeclared identifier
1>DayfromDate.cpp(36): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(36): error C2065: 'start' : undeclared identifier
1>DayfromDate.cpp(40): error C2065: 'start' : undeclared identifier
1>DayfromDate.cpp(44): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(45): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(46): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(47): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(48): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(49): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(50): error C2065: 'cin' : undeclared identifier
1>DayfromDate.cpp(51): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(55): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(58): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(59): error C2065: 'cin' : undeclared identifier
1>DayfromDate.cpp(63): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(69): error C2065: 'string' : undeclared identifier
1>DayfromDate.cpp(69): error C2146: syntax error : missing ';' before identifier 'month'
1>DayfromDate.cpp(69): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(70): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(71): error C2065: 'cin' : undeclared identifier
1>DayfromDate.cpp(71): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(73): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(73): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(73): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(73): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(74): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(74): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(74): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(74): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(75): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(75): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(75): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(75): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(77): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(77): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(81): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(83): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(84): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(90): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(91): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(95): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(96): error C2065: 'cin' : undeclared identifier
1>DayfromDate.cpp(100): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(107): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(108): error C2065: 'cin' : undeclared identifier
1>DayfromDate.cpp(112): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(123): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(124): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(130): error C2065: 'string' : undeclared identifier
1>DayfromDate.cpp(130): error C2146: syntax error : missing ';' before identifier 'bc'
1>DayfromDate.cpp(130): error C2065: 'bc' : undeclared identifier
1>DayfromDate.cpp(131): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(132): error C2065: 'cin' : undeclared identifier
1>DayfromDate.cpp(132): error C2065: 'bc' : undeclared identifier
1>DayfromDate.cpp(134): error C2065: 'bc' : undeclared identifier
1>DayfromDate.cpp(134): error C2065: 'bc' : undeclared identifier
1>DayfromDate.cpp(136): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(136): error C2065: 'bc' : undeclared identifier
1>DayfromDate.cpp(140): error C2065: 'bc' : undeclared identifier
1>DayfromDate.cpp(144): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(145): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(146): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(172): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(174): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(176): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(177): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(181): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(185): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(190): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(190): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(190): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(190): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(194): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(201): error C2065: 'cout' : undeclared identifier
1>DayfromDate.cpp(208): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(209): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(209): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(209): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(210): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(211): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(211): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(212): error C2065: 'month' : undeclared identifier
1>DayfromDate.cpp(212): fatal error C1003: error count exceeds 100; stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited on

My program code.....
Id like to add this is my very first bit of coding and its probably a ratsnest! I had only read the "Basics of C++" in the tutorial section when I wrote it. I was quite prou at the time. Shame I lost the finished program!
In fact it doesn't fit!!! So here is most of it!
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
//This program will find the day from any date between 45BC to 9999AD.
//It uses the Julian Calendar between the dates 45BC and 1752AD. 
//It assumes 45BC (the year the Julian calendar was introduced) is a leap year.
//The year does not exist, 3BC, 2BC, 1BC, 1AD....
//Type 'config' to change the date the Gregorian calendar takes effect.

#include <iostream>
#include <string>
using namespace std;

int main()
{
//Collect Data
int england=1752;
start:
cout << "\nDDDDD           tt";                                     
cout << "\nDD  DD    aa aa tt      eee";
cout << "\nDD   DD  aa aaa tttt  ee   e";  
cout << "\nDD   DD aa  aaa tt    eeeee";       
cout << "\nDDDDDD   aaa aa  tttt  eeeee\n";   
    
cout << "\n CCCCC          lll                lll         tt";
cout << "\nCC    C   aa aa lll   cccc uu   uu lll   aa aa tt     oooo  rr rr";
cout << "\nCC       aa aaa lll cc     uu   uu lll  aa aaa tttt  oo  oo rrr  r";   
cout << "\nCC    C aa  aaa lll cc     uu   uu lll aa  aaa tt    oo  oo rr";
cout << "\n CCCCC   aaa aa lll  ccccc  uuuu u lll  aaa aa  tttt  oooo  rr";
cout << "\n\nby Rik Potts";   
    
    string start;
    cout << "\n\nEnter 'go' to begin or type 'config' for configuration: ";
    cin >> start;
    
    if (start!="go" && start!="config") 
{
    cout << start << " is not a valid entry. Please try again\n\n";
    goto start;
}
    
    if (start=="go") goto findday; else goto config;
    
    //Configuration     
    config:    
    cout << "\nPlease enter the date you want the Gregorian (modern) calendar to take effect.";
    cout << "\n\nDefault is 1752 which is when England began using the Gregorian";
    cout << "\ncalendar. The Gregorian calendar was first introduced in 1582";
    cout << "\nin Venice, France, Spain, Portugal and Netherlands. Germany in 1583";
    cout << ",\nPrussia and Denmark in 1700, Sweden in 1753 and Russia in 1918!\n\n";
    cout << "Please enter the date you want the Gregorian calendar to take effect: ";
    cin >> england;
    cout << "NOTE: You will have to set config each time you run the program.\n\n";
    
    //Find the day (day)   
findday:
    cout << "The Gregorian (modern) calendar will take effect from " << england;
    
    int day;
    cout << "\nPlease enter the day (##): " ;
    cin >> day;
    
    if (day>31 || day<1)
{   
    cout << "\n" << day << " is not a valid day!\nPlease try again\n\n"; 
    goto findday;
}
    
    //Find the month (month)...
month:
    string month;
    cout << "Please enter the Month (abc): ";
    cin >> month;
    
    if (month!="feb" && month!="aug" && month!="mar" && month!="nov" 
    && month!="jun" && month!="sep" && month!="dec" && month!="apr" 
    && month!="jul" && month!="jan" && month!="oct" && month!="may")
{   
    cout << "\n" << month << " is not a valid month!\nPlease try again...\n\n";
    goto month;
}
    
    if (month=="feb" && day>29) 
{
    cout << "\nIt is not possible to have " << day << " days in February!";
    cout << "\nPlease try again\n\n";
    goto findday;
}

     //Find the year (date)...
cent:
    cout << "\nNOTE: If you need a BC date you DO ";
    cout << "NOT need to use a minus sign (-)\n";
    
    //Get the century (cent)
    int cent;
    cout << "Please enter the first two digits of the year (##__): ";
    cin >> cent;
    
    if (cent>99) 
{
    cout << "\n" << cent << " is not a valid entry.\nYou must enter a number below 99.\n";
    goto cent;
}
    
    //Get the year (year)
year:
    int year;
    cout << "Please enter the last two digits of the year (__##): ";
    cin >> year;
    
    if (year>99 || year<0) 
{
    cout << "\n" << year << " is not a valid entry.\nYou must enter a number below 99\n\n";
    goto year;
}

    //make the full year (date)
    int date, numdate;
    date=(100*cent) + year;
    numdate=date;
    
    if (date==0)
{
    cout << "\nThe date 0000 is not valid because the Julian calendar uses 1BC";
    cout << " instead\n\n";
    goto cent;
}

    //Is it a negative or positive year?...
norp:
    string bc;
    cout << "Is the year BC? (y/n) : ";
    cin >> bc;
    
    if (bc!="y" && bc!="n") 
{
    cout << bc << " is not a valid option. Please try again...";
    goto norp;
}
    
    if (bc=="y") date=-date;
    
    if (date<=-46) 
{
    cout << "\nYou entered " << numdate << "BC. The Julian calendar was introduced ";
    cout << "in 45BC.";
    cout << "\nThis makes " << numdate << "BC invalid!\n";
    goto cent;
}
    
    int year2;
    year2=year/4;
    
//Process and Validate Data
    //Is the year a leap year?...
    //Is the year on the gregorian or julian calendar?
    int yl=1, nl=0;
    if (date>=england) goto gregorian;
    
    //Julian calendar
    int jleap;  
    if (date>0 && (date%4==0)) jleap=yl; else jleap=nl;
    if (date<0 && (date%4==-1)) jleap=yl; else jleap=nl;
    goto validation;
   
    //Gregorian calendar
gregorian:
    int gleap;
    gleap = ((date%4==0 && date%100!=0) || date % 400 == 0) ? yl : nl;

    //Is the Month and Day combination correct?
validation:
    if ((jleap==1 || gleap==1) && month=="feb" && day<=29) goto notfeb;
    
    if ((jleap!=1 || gleap!=1) && month=="feb" && day==29) 
{
    cout << "\nThe 29th February is not a valid date because " << date;
    cout << " \nisnt a leap year!\nPlease try again from the beginning\n\n"; 
    goto findday;
}
    
    if (month!="feb") goto notfeb;
    
    if (!(day<=28 && day>=1)) 
{
    cout << day << "\n is not a valid day!\nPlease try again\n\n"; 
    goto findday;
}

notfeb:
    if (month!="sep" && month!="apr" && month!="jun" && month!="nov") goto nsajn;
    
    if (!(day<=30 && day>=1)) 
{
    cout << day << "\n is not a valid day!\nPlease try again\n\n"; 
    goto findday;
}

nsajn:
    if (!(day<=31 && day>=1))
{
    cout << day << "\n is not a valid day!\nPlease try again\n\n"; 
    goto findday;
}

//Interpret Data
    //Calculate the Monthcode
    int monthcode;
    if (month=="aug") monthcode=0;
    if (month=="feb" || month=="mar" || month=="nov") monthcode=1;
    if (month=="jun") monthcode=2;
    if (month=="sep" || month=="dec") monthcode=3;
    if (month=="apr" || month=="jul") monthcode=4;
    if (month=="jan" || month=="oct") monthcode=5;
    if (month=="may") monthcode=6;
    
    //Which calendar to use?
    if (date>=england) goto gregoriansum;

    //Is the leap year compensation required?
    int ujleap, ugleap;
    ujleap=jleap;
    ugleap=gleap;
    if (month!="jan" && month!="feb") ujleap=nl;
    if (month!="jan" && month!="feb") ugleap=nl;
    
    //Julian Formula...
    //(Day + MonthCode + Year + Year/4 + 5 – Century – isLeapJanFeb?) % 7
    int jresult;
    if (date<0) jresult=(day + monthcode - year - (year2) + 5 - cent )%(-7);
    else
    jresult=(day + monthcode + year + (year2) + 5 - cent - ujleap)%7;
    
    goto weekday;
    
    //Gregorian Formula...
gregoriansum:
    //(Day + MonthCode + Year + Year/4 – 2×(Century%4) – isLeapJanFeb?) % 7
    int gresult;
    gresult=(day + monthcode + year + (year2) - (2*(cent%4)) - ugleap)%7;
    
    //Assign day code to word.
weekday:
    int weekday;
    string result;
    weekday = (date<england) ? jresult : gresult;
    if (weekday==0) result="Monday";
    if (weekday==1 || weekday==-6) result="Tuesday";
    if (weekday==2 || weekday==-5) result="Wednesday";
    if (weekday==3 || weekday==-4) result="Thursday";
    if (weekday==4 || weekday==-3) result="Friday";
    if (weekday==5 || weekday==-2) result="Saturday";
    if (weekday==6 || weekday==-1) result="Sunday";
    
Last edited on
Topic archived. No new replies allowed.