Calendar problems

I can get my calendar to get most days correct, except February leap years. It's something with my computeOffset. Anyone see the problem?

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
#include <iostream>
#include <iomanip>
using namespace std;

int getMonth()
{
   int month;

   cout << "Enter a month number: ";
   cin >> month;

   while ( month < 1 || month > 12)
   {
      cout << "Month must be between 1 and 12.\n"
           << "Enter a month number: ";
      cin >> month;
   }

   return month;
}

int getYear()
{
   int year;

   cout << "Enter year: ";
   cin >> year;

   while ( year < 1753)
   {
      cout << "Year must be 1753 or later.\n"
           << "Enter year: ";
      cin >> year;
   }
   return year;
}


bool isLeapYear(int year, int month)
{
   if ((year % 4 == 0 && year % 100 != 0 && month != 1)
       || (year % 400 == 0))
      return true;
   else
      return false;
}

int computeNumberOfDays(int month, int year)
{
   if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8
      || month == 10 || month == 12)
      return 31;
   else if (month == 2 && isLeapYear(year, month))
      return 29;
   else if (month == 2)
      return 28;
   else if (month == 4 || month == 6 || month == 9 || month == 11)
      return 30;
}

/**********************************************************************
 * Will prompt for and save the offset
 ***********************************************************************/
int computeOffset(int month, int year)
{
   int offset = 0;
   int count = year - 1753;
   int addYear = year;

   for (int addYear = 0; addYear < count; addYear++)
   {
      offset = (offset + 365 + isLeapYear(year, month)) % 7;
      year--;
   }
   for (int addMonth = 1; addMonth < month; addMonth++)
   offset = (offset + computeNumberOfDays(addMonth, addYear)) % 7;

   return offset;
}


void displayOffset(int offset)
{
   if (offset == 0)
      cout << setw(8)  << "1";
   else if (offset == 1)
      cout << setw(12) << "1";
   else if (offset == 2)
      cout << setw(16) << "1";
   else if (offset == 3)
      cout << setw(20) << "1";
   else if (offset == 4)
      cout << setw(24) << "1";
   else if (offset == 5)
      cout << setw(28) << "1";

}


void displayCalendar(int numberOfDays, int offset, int month, int year)
{
   int spaces = 0;
   int date = 1;

   cout << endl;

   if (month == 1)
      cout << "January";
   else if (month == 2)
      cout << "February";
   else if (month == 3)
      cout << "March";
   else if (month == 4)
      cout << "April";
   else if (month == 5 )
      cout << "May";
   else if (month == 6 )
      cout << "June";
   else if (month == 7 )
      cout << "July";
 else if (month == 8 )
      cout << "August";
   else if (month == 9 )
      cout << "September";
   else if (month == 10 )
      cout << "October";
   else if (month == 11 )
      cout << "November";
   else if (month == 12 )
      cout << "December";

   cout << ", " << year << endl;
   cout << "  Su  Mo  Tu  We  Th  Fr  Sa" << endl;

   while (numberOfDays >= date)
   {
      if (offset < 6)
      {
         displayOffset(offset);
         date = 2;
         spaces = (offset * 4) + 8;
         offset = 6;
      }


      while (spaces < 28 && (numberOfDays >= date))
      {
         if (date < 10)
            cout << "   " << date;
         else
            cout << "  " << date;

         date += 1;
         spaces += 4;
      }
      cout << endl;
      spaces = 0;
   }
}

int main()
{
   int month = getMonth();
   int year = getYear();
   int numberOfDays = computeNumberOfDays(month, year);
   int offset = computeOffset(month, year);

   displayCalendar(numberOfDays, offset, month, year);

   return 0;
}

Last edited on
The first thing is this:

bool isLeapYear(int year, int month)

A leap year does not depend on the month. It only affects the month > 1.
I had the month in there because otherwise it would affect January
It shouldn't affect the month. What you do is the following:

Q: Is it a leap year?
A: Basically yes, but it is january so no.
I tried it without month and it didn't help. Still has the same issue of it not reading February correctly, and now it also doesn't register January correctly.
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
#include <iostream>
#include <iomanip>
#include <cstdlib>

bool isLeapYear(int year) {
    return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}

int daysInMonth(int year, int month) {
    if (month == 4 || month == 6 || month == 9 || month == 11)
        return 30;
    if (month == 2)
        return isLeapYear(year) ? 29 : 28;
    return 31;
}

// Jan 1, 1753 was a monday (offset 1)
int computeOffset(int year, int month) {
    int a = (year - 1753) /   4;
    int b = (year - 1701) / 100;
    int c = (year - 1601) / 400;
    int leap_years = a - b + c;
    int offset = (1 + year - 1753 + leap_years) % 7;
    for (int m = 1; m < month; m++)
        offset = (offset + daysInMonth(year, m)) % 7;
    return offset;
}

void displayCalendar(int year, int month) {
    const char *month_names[] = {
        "January","February","March","April","May","June",
        "July","August","September","October","November","December"};
    int numberOfDays = daysInMonth(year, month);
    int pos = computeOffset(year, month) + 1;
    std::cout << month_names[month-1] << ", " << year << '\n';
    std::cout << "  Su  Mo  Tu  We  Th  Fr  Sa\n";
    std::cout << std::setw(pos * 4)  << 1;
    for (int date = 2; date <= numberOfDays; ) {
        if (pos++ % 7 == 0) std::cout << '\n';
        std::cout << std::setw(4) << date++;
    }
    std::cout << '\n';
}

int main(int argc, char **argv) {
    if (argc != 3) {
        std::cerr << "Usage: mycal YEAR MONTH\n";
        return 1;
    }
    int year = atoi(argv[1]), month = atoi(argv[2]);
    if (year < 1753) {
        std::cerr << "Error: YEAR must be greater than 1752\n";
        return 1;
    }
    if (month < 1 || month > 12) {
        std::cerr << "Error: MONTH must be from 1 to 12\n";
        return 1;
    }
    displayCalendar(year, month);
}

Last edited on
I appreciate the code, but as a first semester coder I have no clue what most of that stuff means. I don't want a new code. If someone could help me figure out how to change the offset for leap year February by - 1 that's all I need. I have tried to offset -=1 while month == 2 and isLeapYear(year,month) but it doesn't seem to change anything at all.
It's just your code rewritten. isLeapYear and daysInMonth have been corrected (I may have renamed a thing or two, and I reordered the parameters putting year first). The offset calculation has been simplified and corrected and displayCalendar was simplified, too. The only novel thing is taking input from the command line so that it's easier to test. Just forget about that if you want. I think if you look at the code more closely you'll see that it's pretty simple.

What day does your calendar start on for Jan 1, 2000 ? (should be Sat)
What about Jan 1, 2020? (should be Wed)
https://www.timeanddate.com/calendar/?year=2020&country=1
I found the problem. I needed to subract one to the offest if it is a February and a leapyear, but the problem i was running into was the year was being subtracted, so when it would test the year, it was no longer a leap year.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int computeOffset(int month, int year)
{
   int offset = 0;
   int count = year - 1753;
   int addYear = year;
   int origYear = year;

   for (int addYear = 0; addYear < count; addYear++)
   {
      offset = (offset + 365 + isLeapYear(year, month)) % 7;
      year--;
   }
   if ( month == 2 && isLeapYear(origYear,month))
      offset -= 1;

   for (int addMonth = 1; addMonth < month; addMonth++)
      offset = (offset + computeNumberOfDays(addMonth, year)) % 7;

   return offset;
}
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
*    Brother Foushee, CS124
* Author:
*    Braxton Meyer
* Summary:
*    This program
*
*
*    Estimated:  6.0 hrs
*    Actual:     0.0 hrs
*      The most difficult part was
*
*
************************************************************************/

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


char readFile(char fileName[], char board[])
{
   ifstream fin(fileName);
   if(fin.fail())
   {
      cout << "yo this be bad" << fileName << endl;
      return -1;
   }
   for (int i = 0; !fin.eof(); i++)
   {
      fin >> board[i];
      // if (board[i] == '0')
      // board[i] = ' ';
   }
   fin.close();
   return 0;
}

void saveQuit(char board[])
{
   char save;
   cout << "What file would you like to write your board to: ";
   cin >> save;
   //for (int i = 0; i < 2; i++)
   //{
   int i = 0;
      char * pboard;
      pboard = &board[i];
      ofstream fout("save.txt", ios::trunc);
      fout << pboard;
      fout.close();
      //}
   return;
}

void showValues()
{
   return;
}

void editSquare(char board[])
{
   cout << "What are the coordinates of the square: ";
   char coordinates[1];
   cin >> coordinates;
   cout << coordinates[0];
   return;
}

void display(char board[])
{
   cout << "\n   A B C D E F G H I\n";
   int j = 0;
   for (int i = 0; i < 9; i++)
   {
      if ((i % 3) == 0 && i != 0)
         cout << "   -----+-----+-----\n";
      cout << i + 1 << "  ";
      bool newRow = true;
      while ( j < (9 + (i * 9)))
      {
         if (newRow == false)
            cout << "|";
         //spot 1
         if (board[j] == '0')
            cout << "  ";
         else
            cout << board[j] << " ";
         //spot 2
         if (board[j + 1] == '0')
            cout << "  ";
         else
            cout << board[j + 1] << " ";
         //spot 3
         if (board[j + 2] == '0')
            cout << " ";
         else
            cout << board[j + 2];
         newRow = false;

         j += 3;
      }
      cout << endl;
   }
   return;
}

void displayOptions()
{
   cout << "Options:\n"
        << "   ?  Show these instructions\n"
        << "   D  Display the board\n"
        << "   E  Edit one square\n"
        << "   S  Show the possible values for a square\n"
        << "   Q  Save and Quit\n";
}

int interact(char board[])
{
   char input;
   cin >> input;
   switch(input)
   {
      case '?':
         displayOptions();
         break;
      case 'D':
         display(board);
         break;
      case 'E':
         editSquare(board);
         break;
      case 's':
      case 'S':
         break;
      case 'q':
      case 'Q':
         saveQuit(board);
         return -1;
         break;
   }
   return 0;
}
/**********************************************************************
* main reads the list, determines the speed of the searches, and outputs
* the results.
***********************************************************************/
int main()
{
   char fileName[256];
   cout << "Where is your board located? ";
   cin >> fileName;
   char board[81];
   readFile(fileName, board);
   displayOptions();
   display(board);
   int choice = 0;
   while (choice != -1)
      choice = interact(board);
   return 0;
}
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
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

/**********************************************************************
 * This will take the users input
 ***********************************************************************/
void askQuestion(char prompt[], char response[])
{
   prompt[0] = '\t';
   prompt[1] = toupper(prompt[1]);

   for (int i = 2; prompt[i]; i++)
   {
      if ( prompt[i] == '_')
         prompt[i] = ' ';
      else
         prompt[i] = tolower(prompt[i]);
   }

   cout << prompt << ": ";

   for (int i = 0; i < 80; i++)
   {
      response[i] = '\0';
   }
   cin.getline(response,80);
}

/**********************************************************************
 * This function will read a file
 ***********************************************************************/
float readFile(char fileName[], char story[][80])
{
   ifstream fin(fileName);

   if (fin.fail())
   {
      cout << "Error reading file " << "\"" <<  fileName << "\"" << endl;
      return -1;
   }

   int i = 0;

   for (i = 0; !fin.eof(); i++)
   {
      fin >> story[i];
      if ( story[i][0] == ':' && isalpha(story[i][1]))
      {
         char response[80];
         askQuestion(story[i], response);
         for (int j = 0; j < 80; j++)
            story[i][j] = response[j];
      }
   }
   story[i][0] = ' ';
   fin.close();
   return i;
}


/**********************************************************************
 * This will get the name of the file
 ***********************************************************************/
void getFile(char fileName[])
{
   cout << "Please enter the filename of the Mad Lib: ";
   cin >> fileName;
   cin.ignore();
}

/**********************************************************************
 * Will replace special characters with correct punctuation
 ***********************************************************************/
void replacePunctuation(char story[][80])
{
   for (int i = 0; story[i][0] != ' '; i++)
   {
      if ( story[i][0] == ':')
      {
         if (story[i][1] == '!')
         {
            story[i][0] = '\n';
            story[i][1] = '\0';
         }
         else if (story[i][1] == '<')
         {
            story[i][0] = '<';
            story[i][1] = '\0';
         }
         else if (story[i][1] == '>')
         {
            story[i][0] = '>';
            story[i][1] = '\0';
         }
         else if (story[i][1] == '.')
         {
            story[i][0] = '.';
            story[i][1] = '\0';
  }
         else if (story[i][1] == ',')
         {
            story[i][0] = ',';
            story[i][1] = '\0';
         }

      }
   }
}


/**********************************************************************
 * This will display the story onto the screen
 ***********************************************************************/
void display(char story[][80], int numWords)
{
   for (int i = 0; i < numWords; i++)
   {
      char current = *story[i];
      char next = *story[i + 1];
      bool addSpace = true;

      cout << story[i];
      {
         if ( next == '\n' || next == '.' || next == ',' || next == '>'
              || next == ' ')
            addSpace = false;
         else if (current == '\n' || current == ' ' || current == '<'
                  || (current == '.' && !isalpha(next)))
            addSpace = false;
         else
            addSpace = true;
      }
      {
         if ( addSpace == true)
            cout << " ";
      }
   }
   cout << endl;
}



/**********************************************************************
 * Will ask for input and then will put input into a story
 ***********************************************************************/
int main()
{
   char fileName[256];
   char story[32][80];
   char answer;
   bool playAgain = false;
   do
   {
      getFile(fileName);
      int numWords = readFile(fileName, story);
      replacePunctuation(story);
      cout << endl;
      display(story, numWords);
      cout  << "Do you want to play again (y/n)? ";
      cin >> answer;
      if ( answer == 'y')
         playAgain = true;
      else
         playAgain = false;
   }
   while (playAgain);

   cout << "Thank you for playing." << endl;

   return 0;
}
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#include <fstream>
#include <string>
#include <iostream>
using namespace std;

/**********************************************************************
 * Gets the file name
 ***********************************************************************/
void getFile(char fileName[])
{
   cout << "Where is your board located? ";
   cin >> fileName;
}

/**********************************************************************
 * Takes information from a file and turns it into an array
 ***********************************************************************/
int readFile(char fileName[], char board[][10])
{
   ifstream fin(fileName);

   if (fin.fail())
   {
      cout << "Unable to read file: " << fileName << endl;
      return -1;
   }
   for (int k = 0; k < 9; k++)
   {
      for (int j = 0; j < 9; j++)
         fin >> board[k][j];
   }
   fin.close();

   return 0;
}

/**********************************************************************
 * Places the sudoku board onto the screen
 ***********************************************************************/
void display(char board[][10])
{
   cout << "   A B C D E F G H I" << endl;

   for ( int i = 0; i < 9; i++)
   {
      if (( i % 3) == 0 && i != 0)
         cout << "   -----+-----+-----\n";
      cout << i + 1 << "  ";
      for (int j = 0; j < 9; j++)
      {
         if (board[i][j] == '0')
            cout << " ";
         else
            cout << board[i][j];
         if (j == 2 || j == 5)
            cout << "|";
         if (j != 8 && j != 2 && j != 5)
            cout << " ";
      }
      cout << endl;
   }

}

/**********************************************************************
 * This will check the valid numbers for a certain grid location
 ***********************************************************************/
char validNumbers(char board[][10], char square[], char guess)
{

   int letter = square[0] - 65;
   int number = square[1] - 49;

   char validRow[9];
   char validCol[9];
   char validSquare[9];
   bool valid = true;

   for (int i = 0; i < 9; i++)
   {
      if (guess == board[number][i])
      {
         valid = false;
      }
      if (guess == board[i][letter])
      {
         valid = false;
      }
   }

   for (int j = 0; j < 3; j++)
   {
      for (int i = 0; i < 3; i++)
      {
         if (guess ==  board[(number / 3) * 3 + i ][letter / 3 * 3 + j])
         {
            valid = false;
         }
      }
   }

   return valid;
}

/**********************************************************************
 * Asks for a square and a value to put in it
 ***********************************************************************/
int editSquare(char board[][10])
{
   char guess;
   bool empty = false;
   bool valid = true;
   char square[2];
   char validNumber[9];
   char boardLetter;
   char boardNumber;

   cout << "What are the coordinates of the square: ";
   cin >> square;
   if (isalpha(square[0]))
      square[0] = toupper(square[0]);
   else
   {
      boardLetter = square[1];
      boardNumber = square[0];
      square[0] = boardLetter;
      square[1] = boardNumber;
      square[0] = toupper(square[0]);
   }


   int letter = square[0] - 65;
   int number = square[1] - 49;

   if (board[number][(letter)] == '0')
      empty = true;

   if (empty == true)
   {
      cout << "What is the value at '" << square[0] << square[1] << "\': ";
      cin >> guess;

   }

   else
   {
      cout << "ERROR: Square " << "\'" << square[0];
      cout << square[1] <<  "\' is filled\n";
   }
   valid = validNumbers(board, square, guess);

   if (empty == true && valid == false )
   {
      cout << "ERROR: Value \'" << guess << "\' in square \'"
           << square[0] << square[1] << "\' is invalid\n";
   }

   else if (empty == true && valid == true)
      board[number][letter] = guess;

}

/**********************************************************************
 * Saves the board into a file
 ***********************************************************************/
void saveQuit(char board[][10])
{
   char newFile[256];

   cout << "What file would you like to write your board to: ";
   cin >> newFile;

   ofstream fout(newFile, ios::trunc);

   for (int i = 0; i < 9; i++)
   {
      for (int j = 0; j < 9; j++)
      {
         fout << board[i][j] << " ";
      }
      fout << endl;
   }
   fout.close();

   cout << "Board written successfully\n";
}

/**********************************************************************
 * Display options
 ***********************************************************************/
void options()
{
   cout << "Options:" << endl;
   cout << "   ?  Show these instructions" << endl;
   cout << "   D  Display the board" << endl;
   cout << "   E  Edit one square" << endl;
   cout << "   S  Show the possible values for a square" << endl;
   cout << "   Q  Save and Quit" << endl;
   cout << endl;
}

/**********************************************************************
 * Displays the valid numbers for a square
 ***********************************************************************/
void showValidNumbers(char board[][10])
{
   char square[2];
   int count = 0;
   char validNumber[9];
   bool valid = false;
   char boardNumber;
   char boardLetter;

   cout << "What are the coordinates of the square: ";
   cin >> square;

   if (isalpha(square[0]))
      square[0] = toupper(square[0]);

   else
   {
      boardLetter = square[1];
      boardNumber = square[0];
      square[0] = boardLetter;
      square[1] = boardNumber;
      square[0] = toupper(square[0]);
   }


   int letter = square[0] - 65;
   int number = square[1] - 49;



   cout << "The possible values for \'"
        << square[0] << square[1] << "\' are: ";

   for (int i = 1; i < 10; i++)
   {
      char guess = (char)(i + '0');

      valid = validNumbers(board, square, guess);

      if (valid == true)
      {
         count++;
      }
   }

   for (int j = 1; j < 10; j++)
   {
      char guess = (char)(j + '0');

      valid = validNumbers(board, square, guess);

      if (valid == true)
      {
         switch (count)
         {
            case 1:
               cout << j;
               break;
            default:
               cout << j << ", ";
               count--;
         }
      }
   }
}


/**********************************************************************
 * Allows for user input to interact with the game
 ***********************************************************************/
int interact(char board[][10])
{
   char interact;
   char input;

   cout << "> ";
   cin >> interact;
   switch (interact)
   {
      case '?':
         options();
         break;
      case 'D':
      case 'd':
         display(board);
         break;
      case 'E':
      case 'e':
         editSquare(board);
         break;
      case 'S':
      case 's':
         showValidNumbers(board);
         cout << endl;
         break;
      case 'Q':
      case 'q':
         saveQuit(board);
         return -1;
         break;

   }
   return 0;
}

/**********************************************************************
 * Allows a player to play sudoku
 ***********************************************************************/
int main()
{
   char fileName[256];
   char board[10][10];
   int input;

   getFile(fileName);
   readFile(fileName, board);
   options();
   display(board);

   while (input != -1)
   {
      cout << endl;
  input = interact(board);
   }
   return 0;
}
You just seem to be dumping copies of your code into this thread, without asking any questions or mentioning any problems.

Why?
Topic archived. No new replies allowed.