Hello everybody!

I made a program which is able to calculate your age. You can find the source code below this text. There is already posted an article like this on http://www.daniweb.com/software-development/cpp/code/331349/c-code-for-simple-age-calculator

But, my program is:
- Without mistakes, it doesn't give your computer wrong instructions.
- More accurate, because my program calculates also the days instead of only the years and months.

I wrote this program in Dutch, and later I translated it into the English language. If you are using the program, everything is in English. But in the source code you can still find Dutch words like "jaar", "maand", "dag" etc. Just ignore them. If you are using the program, you won't see those words, so don't worry.

Here is the source code:

#include <iostream>
using namespace std;

int main()
{
    system("CLS");
    int bjaar, bmaand, bdag, hjaar, hmaand, hdag, ljaar, lmaand, ldag, tjaar, tmaand, tdag;
    char vraag1;
    cout << "\n\n\t\t Mark Wierings's Age Calculator \n\n";
    cout << "In which year where you born? (Example: 1995) ";
    cin >> bjaar;
    cout << endl << "In which month were you born? " << endl << endl;
    cout << " 1) January \n 2) February \n 3) March \n 4) April \n 5) May \n 6) June \n 7) July";
    cout << endl << " 8) August \n 9) September \n 10) October \n 11) November \n 12) December";
    cout << endl << endl << "Enter a value: ";
    cin >> bmaand;
    while(bmaand <= 0 || bmaand > 12)
    {
              system("CLS");
              cout << endl << bmaand << " is an invalid value. ";
              cout << "1 to 12 are valid values." << endl;
              cout << "Enter a valid value: ";
              cin >> bmaand;
    }
    cout << endl << "On which day of the month were you born? ";
    cin >> bdag;
    if(bmaand == 1 || bmaand == 3 || bmaand == 5 || bmaand == 7 || bmaand == 8 || bmaand == 10 || bmaand == 12)
    {
          while(bdag <= 0 || bdag > 31)
          {
                  system("CLS");
                  cout << endl << bdag << " is an invalid value for a day of a month." << endl;
                  cout << "Enter a valid value. 1 to 31 are valid values: ";
                  cin >> bdag;
          }

    }
    if(bmaand == 4 || bmaand == 6 || bmaand == 9 || bmaand == 11)
    {
          while(bdag <= 0 || bdag > 30)
          {
                  system("CLS");
                  cout << endl << bdag << " is an invalid value for a day of a month." << endl;
                  cout << "Enter a valid value. 1 to 30 are valid values: ";
                  cin >> bdag;
          }

    }
    if(bmaand == 2)
    {
              if(bjaar%4 == 0)
              {
                         if(bjaar%100 == 0 && bjaar%400 != 0)
                         {
                                      while(bdag <= 0 || bdag > 28)
                                      {
                                                 system("CLS");
                                                 cout << endl << bdag << " is an invalid value for a day of a month." << endl;
                                                 cout << "Enter a valid value. 1 to 28 are valid values: ";
                                                 cin >> bdag;
                                      }
                         }
                         else
                         {
                                      while(bdag <= 0 || bdag > 29)
                                      {
                                                 system("CLS");
                                                 cout << endl << bdag << " is an invalid value for a day of a month." << endl;
                                                 cout << "Enter a valid value. 1 to 29 are valid values: ";
                                                 cin >> bdag;
                                      }    
                         }
              }
              else
              {
                   while(bdag <= 0 || bdag > 28)
                   {
                              system("CLS");
                              cout << endl << bdag << " is an invalid value for a day of a month." << endl;
                              cout << "Enter a valid value. 1 to 28 are valid values: ";
                              cin >> bdag;
                   }
              }
    }
    if(bmaand == 1)
    {
              system("CLS");
              cout << endl << "You were born on the " << bdag << "th January " << bjaar << "." << endl;
              cout << endl << "Is that right? (Y/N) ";
              cin >> vraag1;
              if(vraag1 != 'Y' && vraag1 != 'y')
              {
                        cout << endl << "The program will be restarted so you can enter your ";
                        cout << "data again." << endl << endl;
                        system("pause");
                        main();
              }
    }
    if(bmaand == 2)
    {
              system("CLS");
              cout << endl << "You were born on the " << bdag << "th February " << bjaar << "." << endl;
              cout << endl << "Is that right? (Y/N) ";
              cin >> vraag1;
              if(vraag1 != 'Y' && vraag1 != 'y')
              {
                        cout << endl << "The program will be restarted so you can enter your ";
                        cout << "data again." << endl << endl;
                        system("pause");
                        main();
              }
    }
    if(bmaand == 3)
    {
              system("CLS");
              cout << endl << "You were born on the " << bdag << "th March " << bjaar << "." << endl;
              cout << endl << "Is that right? (Y/N) ";
              cin >> vraag1;
              if(vraag1 != 'Y' && vraag1 != 'y')
              {
                        cout << endl << "The program will be restarted so you can enter your ";
                        cout << "data again." << endl << endl;
                        system("pause");
                        main();
              }
    }
    if(bmaand == 4)
    {
              system("CLS");
              cout << endl << "You were born on the " << bdag << "th April " << bjaar << "." << endl;
              cout << endl << "Is that right? (Y/N) ";
              cin >> vraag1;
              if(vraag1 != 'Y' && vraag1 != 'y')
              {
                        cout << endl << "The program will be restarted so you can enter your ";
                        cout << "data again." << endl << endl;
                        system("pause");
                        main();
              }
    }
    if(bmaand == 5)
    {
              system("CLS");
              cout << endl << "You were born on the " << bdag << "th May " << bjaar << "." << endl;
              cout << endl << "Is that right? (Y/N) ";
              cin >> vraag1;
              if(vraag1 != 'Y' && vraag1 != 'y')
              {
                        cout << endl << "The program will be restarted so you can enter your ";
                        cout << "data again." << endl << endl;
                        system("pause");
                        main();
              }
    }
    if(bmaand == 6)
    {
              system("CLS");
              cout << endl << "You were born on the " << bdag << "th June " << bjaar << "." << endl;
              cout << endl << "Is that right? (Y/N) ";
              cin >> vraag1;
              if(vraag1 != 'Y' && vraag1 != 'y')
              {
                        cout << endl << "The program will be restarted so you can enter your ";
                        cout << "data again." << endl << endl;
                        system("pause");
                        main();
              }
    }
    if(bmaand == 7)
    {
              system("CLS");
              cout << endl << "You were born on the " << bdag << "th July " << bjaar << "." << endl;
              cout << endl << "Is that right? (Y/N) ";
              cin >> vraag1;
              if(vraag1 != 'Y' && vraag1 != 'y')
              {
                        cout << endl << "The program will be restarted so you can enter your ";
                        cout << "data again." << endl << endl;
                        system("pause");
                        main();
              }
    }
    if(bmaand == 8)
    {
              system("CLS");
              cout << endl << "You were born on the " << bdag << "th August " << bjaar << "." << endl;
              cout << endl << "Is that right? (Y/N) ";
              cin >> vraag1;
              if(vraag1 != 'Y' && vraag1 != 'y')
              {
                        cout << endl << "The program will be restarted so you can enter your ";
                        cout << "data again." << endl << endl;
                        system("pause");
                        main();
              }
    }
    if(bmaand == 9)
    {
              system("CLS");
              cout << endl << "You were born on the " << bdag << "th September " << bjaar << "." << endl;
              cout << endl << "Is that right? (Y/N) ";
              cin >> vraag1;
              if(vraag1 != 'Y' && vraag1 != 'y')
              {
                        cout << endl << "The program will be restarted so you can enter your ";
                        cout << "data again." << endl << endl;
                        system("pause");
                        main();
              }
    }
    if(bmaand == 10)
    {
              system("CLS");
              cout << endl << "You were born on the " << bdag << "th October " << bjaar << "." << endl;
              cout << endl << "Is that right? (Y/N) ";
              cin >> vraag1;
              if(vraag1 != 'Y' && vraag1 != 'y')
              {
                        cout << endl << "The program will be restarted so you can enter your ";
                        cout << "data again." << endl << endl;
                        system("pause");
                        main();
              }
    }
    if(bmaand == 11)
    {
              system("CLS");
              cout << endl << "You were born on the " << bdag << "th November " << bjaar << "." << endl;
              cout << endl << "Is that right? (Y/N) ";
              cin >> vraag1;
              if(vraag1 != 'Y' && vraag1 != 'y')
              {
                        cout << endl << "The program will be restarted so you can enter your ";
                        cout << "data again." << endl << endl;
                        system("pause");
                        main();
              }
    }
    if(bmaand == 12)
    {
              system("CLS");
              cout << endl << "You were born on the " << bdag << "th December " << bjaar << "." << endl;
              cout << endl << "Is that right? (Y/N) ";
              cin >> vraag1;
              if(vraag1 != 'Y' && vraag1 != 'y')
              {
                        cout << endl << "The program will be restarted so you can enter your ";
                        cout << "data again." << endl << endl;
                        system("pause");
                        main();
              }
    }
    system("CLS");
    cout << endl << "Which year is it now? ";
    cin >> hjaar;
    while(hjaar < bjaar)
    {
                cout << endl << "Your birthyear can't be bigger than the current year." << endl;
                cout << "Enter a valid year: ";
                cin >> hjaar;
    }
    cout << endl << "Which month is it now? " << endl << endl;
    cout << " 1) January \n 2) February \n 3) March \n 4) April \n 5) May \n 6) June \n 7) July";
    cout << endl << " 8) August \n 9) September \n 10) October \n 11) November \n 12) December";
    cout << endl << endl << "Enter a value: ";
    cin >> hmaand;
    while(hmaand <= 0 || hmaand > 12)
    {
              system("CLS");
              cout << endl << bmaand << " is an invalid value. ";
              cout << "1 to 12 are valid values." << endl;
              cout << "Enter a valid value: ";
              cin >> hmaand;
    }
    while(hjaar == bjaar && hmaand < bmaand)
    {
                system("CLS");
                cout << endl << "You aren't born yet. This program is only intended for the people who are born" << endl;
                cout << "Just wait a few months, or enter a valid current month: ";
                cin >> hmaand;
    }
    cout << endl << "Which day of the month is it now? ";
    cin >> hdag;
    if(hmaand == 1 || hmaand == 3 || hmaand == 5 || hmaand == 7 || hmaand == 8 || hmaand == 10 || hmaand == 12)
    {
          while(hdag <= 0 || hdag > 31)
          {
                  system("CLS");
                  cout << endl << bdag << " is an invalid value for a day of the month." << endl;
                  cout << "1 to 31 are valid values. Enter a valid value: ";
                  cin >> bdag;
          }

    }
    if(hmaand == 4 || hmaand == 6 || hmaand == 9 || hmaand == 11)
    {
          while(hdag <= 0 || hdag > 30)
          {
                  system("CLS");
                  cout << endl << bdag << " is an invalid value for a day of the month." << endl;
                  cout << "1 to 30 are valid values. Enter a valid value: ";
                  cin >> bdag;
          }

    }
    if(hmaand == 2)
    {
              if(hjaar%4 == 0)
              {
                         if(hjaar%100 == 0 && hjaar%400 != 0)
                         {
                                      while(hdag <= 0 || hdag > 28)
                                      {
                                                 system("CLS");
                                                 cout << endl << bdag << " is an invalid value for a day of the month." << endl;
                                                 cout << "1 to 28 are valid values. Enter a valid value: ";
                                                 cin >> bdag;
                                      }
                         }
                         else
                         {
                                      while(hdag <= 0 || hdag > 29)
                                      {
                                                 system("CLS");
                                                 cout << endl << bdag << " is an invalid value for a day of the month." << endl;
                                                 cout << "1 to 29 are valid values. Enter a valid value: ";
                                                 cin >> bdag;
                                      }    
                         }
              }
              else
              {
                   while(hdag <= 0 || hdag > 28)
                   {
                              system("CLS");
                              cout << endl << bdag << " is an invalid value for a day of the month." << endl;
                              cout << "1 to 28 are valid values. Enter a valid value: ";
                              cin >> bdag;
                   }
              }
    }
    if(hjaar == bjaar && hmaand == bmaand && hdag < bdag)
    {
             system("CLS");
             cout << endl << "You aren't born yet. This program is only intended for the people who are born." << endl;
             cout << "Just wait a few days, or enter a valid day: ";
             cin >> hdag;
    }
    cout << endl << "The system is calculating your age..." << endl << endl;
    ljaar = hjaar - bjaar;
    lmaand = hmaand - bmaand;
    ldag = hdag - bdag;
    if(lmaand < 0)
    {
              ljaar = ljaar - 1;
              lmaand = 12 + lmaand;
    }
    if(ldag < 0 && lmaand == 0)
    {
            ljaar = ljaar - 1;
            lmaand = 12 - 1;
            if(hmaand == 1 || hmaand == 3 || hmaand == 5 || hmaand == 7 || hmaand == 8 || hmaand == 10 || hmaand == 12)
            {
                   ldag = 31 + ldag;   
            }
            if(hmaand == 4 || hmaand == 6 || hmaand == 9 || hmaand == 11)
            {
                   ldag = 30 + ldag;
            }
            if(hmaand == 2)
            {
                      ldag = 28 + ldag;
                      if(hjaar%4 == 0)
                      {
                                 ldag = 29 + ldag;
                                 if(hjaar%100 == 0 && hjaar%400 != 0)
                                 {
                                              ldag = 28 + ldag;
                                 }
                      }
            }
    }
    if(ldag < 0 && lmaand != 0)
    {
            lmaand = lmaand - 1;
            if(hmaand == 1 || hmaand == 3 || hmaand == 5 || hmaand == 7 || hmaand == 8 || hmaand == 10 || hmaand == 12)
            {
                   ldag = 32 + ldag;   
            }
            if(hmaand == 4 || hmaand == 6 || hmaand == 9 || hmaand == 11)
            {
                   ldag = 31 + ldag;
            }
            if(hmaand == 2)
            {
                      ldag = 29 + ldag;
                      if(hjaar%4 == 0)
                      {
                                 ldag = 30 + ldag;
                                 if(hjaar%100 == 0 && hjaar%400 != 0)
                                 {
                                              ldag = 29 + ldag;
                                 }
                      }
            }
    }
    cout << "Birthyear: " << bjaar << endl;
    cout << "Birthmonth: " << bmaand << endl;
    cout << "Birthday: " << bdag << endl << endl;
    if(ldag != 1 && lmaand != 1)
    {
            cout << "You are " << ljaar << " years, " << lmaand << " months and " << ldag << " days old.";
    }
    if(ldag == 1 && lmaand == 1)
    {
            cout << "You are " << ljaar << " years, " << lmaand << " month and " << ldag << " day old.";
    }
    if(ldag != 1 && lmaand == 1)
    {
            cout << "You are " << ljaar << " years, " << lmaand << " month and " << ldag << " days old.";
    }
    if(ldag == 1 && lmaand != 1)
    {
            cout << "You are " << ljaar << " years, " << lmaand << " months and " << ldag << " day old.";
    }
    if(ljaar == 0 && lmaand == 0 && ldag == 0)
    {
             cout << endl << "You are just born!" << endl;
    }
    if(ljaar != 0 && lmaand == 0 && ldag == 0)
    {
             cout << endl << endl << "Happy birthday! You have become " << ljaar << " years old now!" << endl;
    }
    cout << endl << endl;

    system("pause");
    return 0;
}

To use this program, follow these instructions.

  1. Copy the source code.
  2. Paste the source code into a compiler. (For example: Dev-C++, Code::Blocks, Visual Studio or whatever you like to use)
  3. Save it, give it a name, compile it, use it.
  4. Have fun.

I am a beginner with C++, so if you think there is an easier way to write this program, let me know. :-D

What would happen if I were to type "five" for the year I was born?

What would happen if I were to type "five" for the year I was born?

The program will crash. You have to fill in a number.

Indeed, but I meant rhetorically, it is good prctice to ensure
the user enter an expected value.

Just a tip for you that is all.

Suzie999

I have tested my program already. I solved every single mistake which I have made. The program also takes to account with leap years and with correctionyears.

It is a perfect program now. :-D

No! no it is not, I can crash it with a simple wrong entry.
It is quite fundamentally flawed.

Suzie999
It is. The program will prevent you from entering invalid data.

For example: the birthyear you have entered is bigger than the current year you have entered. The program tells you that the current year you have entered is invalid because the birthyear can't be bigger than the current year, and asks you to enter a valid current year.

When you enter characters instead of numbers, the program doesn't know what to do with it, so it crashes.

It is quite fundamentally flawed

Agreed. And the formatting is terrible.

Calling system() is not necessary and not portable. When compiling on my Linux system the program doesn't work as advertised. On my Windows system I get nauseous with all the blinking screens.

Too many convoluted IF statements where SWITCH statements would be cleaner.

Calling main() is not OK. main() is the entry point to the program, not a recursive function. Very bad!!!

I have tested my program already. I solved every single mistake which I have made.

Obviously not.

WaltP
I haven't learnt the SWITCH-statement yet. I am just a beginner.

This program compiles perfect. My compiler, Dev-C++, is able to compile it whitout any problems. The program is also running fine. It is a pretty accurate age calculator which isn't giving your computer wrong instructions.

I wonder which compiler you are using, because my compiler compiles it without any problem. My computer, Windows 2000, is also running it without having any problems.

In some if-statements I am using main(); to restart the program. That is not bad!

My program doesn't have mistakes, because I already solved them. :-D

If you are beginner, then you should heed the advice you are being given.
If you believe that it is OK to have your program crash with a simple
incorrect entry then the coding path ahead is going to be long and hard.

Another dismissive and arrogant foolhardy post from you will confirm my
suspisions that you are just trolling.

Good luck for the future.

I'm Out.

Suzie999

Okay, so you think I wrote a full source code for a program, just to troll you?

What is wrong with you?

If you are beginner, then you should heed the advice you are being given.
If you believe that it is OK to have your program crash with a simple
incorrect entry then the coding path ahead is going to be long and hard.

Sorry, but she's absolutely correct.

What would you do if your favorite game crashed because you accidentally entered "rt" instead of "45"? Learn from the advice. Good students don't argue, they listen.

My program doesn't have mistakes, because I already solved them. :-D

This is the difference between a beginner and someone with experience. You think you've made no mistakes and your program has no bugs. We know we've made mistakes and are grateful when someone finds a bug.

Drop the ego dude, you're never going to get beyond the beginner stage if you think you're perfect.

I wonder which compiler you are using, because my compiler compiles it without any problem. My computer, Windows 2000, is also running it without having any problems.

Well, my compiler and my computer won't, therefore it's not a good program. A good program should compile with any standard C++ compiler, on any system.

In some if-statements I am using main(); to restart the program. That is not bad!

Who says? You? Or the people that designed C++? I'm going to listen to the designers, thank you very much. They say it's bad.

My program doesn't have mistakes, because I already solved them. :-D

As decepticon said...

How long have you been programming?

WaltP
Okay, which code do I have to use so my program won't crash if I enter a character instead of a value?

deceptikon
I said my program doesn't have mistakes because my program isn't the computer giving wrong instuctions. I tested it by myself.

WaltP
You are using a very bad C++ compiler if it isn't even able to compile this source code.

Who says? You? Or the people that designed C++? I'm going to listen to the designers, thank you very much. They say it's bad.

If you think that using main(); is wrong, then which code do I have to use to restart my program?

I am programming for a few months.

commented: Whzat an egotistical ass -- claiming a 25 year old compiler is better than a compiler from the past 10 years! +0

I'm starting to think that you're a troll. The utter senselessness of continually claiming that you're a beginner but also rejecting all advice on the grounds that you're perfect suggests an attempt to get a rise out of people.

Not to be pricky or such but markwiering, you should listen to these fine gentlemen, because they really know what they are talking about.
Frankly when I look at your source code I see a lot of if statements whereas some other implementation would have saved your processor time/life etc.
You don't want to get advices from others but you strongly underline the face that you're a beginner. Being a beginner and not wanting to get advices from someone that cand help you is just plain dumbness.

Okay, which code do I have to use so my program won't crash if I enter a character instead of a value?

You could implement some form of validation, if you don't know what that is, you can check in your coursebook.

You are using a very bad C++ compiler if it isn't even able to compile this source code.

Note that there are specific items from C++ that work only on some OS. Linux is different from Windows, and if you implement some specific items from Windows, don't expect to work on Linux.

You are using a very bad C++ compiler if it isn't even able to compile this source code.

All of your souce code is in one function, and that function is the specific starting function of your program - what is wrong with you? Haven't you heard about other functions, classes maybe, structures? This is not Python to just use any function as the starting point of your program, then to recursivelly call it to "restart your program".

So in conclusion, as deceptikon and WaltP said: loose the attitude, and start learning from others advices, and from your own mistakes. Even if you think that your program is flawless, it's not. You can't just put your hand into a flame and convice other that you won't get burned.

commented: Nice point of view. +0

decepticon

I still don't get why you are thinking I'm a troll. Give me a clear explanation.

WaltP was negative about the fact that I have used main(); and about the fact that my program will crash if you enter a character instead of a value. I asked WaltP which code I have to use to restart my program is main(); is not good enough, and which code I have to use so my program won't crash if you enter a character instead of a value.

As I said; I am a beginner who wants to learn C++ better.

Give me a clear explanation.

I fail to see what's unclear about the hypocrisy here. You claim to be a beginner, someone who by definition isn't perfect and will make a greater than average number of mistakes that go unnoticed. You also claim that your program has no problems and cannot be improved despite being shown otherwise.

This alone doesn't make you a troll, but refusing to listen to anyone who points out flaws raises red flags.

As I said; I am a beginner who wants to learn C++ better.

Bullshit. You've rejected any attempts to teach you and stubbornly insist that your code is without flaws. With that attitude, the clueful people won't want to help you learn C++ better. I certainly have no incentive to review your code for you because I'm reasonably sure it would accomplish nothing and be a huge waste of my time.

Lucaci Andrew

All of your souce code is in one function, and that function is the specific starting function of your program - what is wrong with you? Haven't you heard about other functions, classes maybe, structures? This is not Python to just use any function as the starting point of your program, then to recursivelly call it to "restart your program".

In C++, it isn't necessary to use different functions in this situation. It is a possibility, but the compiler will still be able to compile the code fine, even if it has only one function. The program, with only one long function, will also run without any problems.

Just like you can use "\n" to go to the next line, or "endl". It's exactly the same.

Note that there are specific items from C++ that work only on some OS. Linux is different from Windows, and if you implement some specific items from Windows, don't expect to work on Linux.

Of course there are different operating systems. Linux is different than Windows, but the program language, C++, should be the same.

Now, I want to fix the problem that if I enter a character instead of a value, the program will crash. WaltP and deceptikon are refusing to help me. They just say that my program is bad and that I am trolling.

In programing there are a lot of things that aren’t necessary for you to do. There are also a lot of things that you can do but shouldn’t do. The fact that the language or the compiler you are using allows you to do it doesn’t mean you should. The best thing to do is to get into the habit of programing in the standard manner. This includes putting code into functions that is going to be reused like your calculation to determine if it is a leap year or not. Your main function should mainly be an entry point for your program, you definitely shouldn’t be calling it from anywhere in your program. I understand that for small projects this might seem annoying but it gets you into the habit of doing it.

If I was you I would listen to what the people here are telling you instead of arguing saying that since it works it is okay. WaltP and deceptikon have some invaluable advice to give and when they give advice I don’t blindly ignore it. That’s not to say you shouldn’t argue a point if you don’t agree but if you are going to, make sure you have some clear examples and/or references to back you up. Learning to code never stops and it takes time to just master the basics. Well there is my two cents.

WaltP and deceptikon are refusing to help me.

If you actually accepted help instead of rejected every suggestion, we'd be more inclined to make a serious attempt at helping you. But since you stubbornly refuse to listen to any advice and act like a know-it-all, we aren't going to bother. Well, at least, I won't. I can't really speak for Walt, but I suspect he feels the same way.

It's a shame too, I could help you improve this program and your C++ abilities drastically. But I know a lost cause when I see one.

NathanOliver

  1. I am using main(); to restart the program. If you know a better code to do that, give me the code.
  2. My program will crash if you enter a character instead of a value. Do you know with which code I can solve that problem?
  3. WaltP and Suzie999 aren't helping or giving advises. They are just bashing my program, without telling me which code I have to use to solve the problems I have made.

Well to fix number 1 breaking your code into functions and using loops will eliminate the need to call main. To fix number 2 you should take your input in as a string and validate the data that way. You can take a look at this thread to get some ideas http://www.daniweb.com/software-development/cpp/threads/432195/bit-of-weirdness. As far as 3 goes they didn’t start off bashing your program. They gave you some constructive criticism of your code and totally disregarded it and decided to argue about the things they pointed out.

Hi markwiering,

I hear where you're coming from. You're still a fairly raw beginner, so for you, having code that appears to work fine when the expected input is provided probably feels like a good result. And in one sense it is. But you can probably understand where the others are coming from, too. Your programme doesn't guard against unexpected input, and in a real-world programme that'd be a major issue.

If you don't understand how to guard against it, at least understand that at some point this is going to matter to you.

There are quite a few things that someone more experienced with C++ would do differently, which is why you're attracting the comments. If the comments are beyond your current understanding, maybe come back and take a look at this code in a couple of months time.

All the best with your coding.

Just like you can use "\n" to go to the next line, or "endl". It's exactly the same.

In fact, they're not exactly the same. It's quite possible that the difference between the two is irrelevent for this programme, but they're not the same and at some point it may matter. Here's where you can begin helping yourself, by acquiring a good C++ reference and reading up a little -- if not now then later -- and avoiding making concrete statements unless you're absolutely positive about them. It takes time to become proficient in any language, and that's certainly true of C++.

Once again, good luck, enjoy the ride, and strive to be the best you can be.

WaltP was negative about the fact that I have used main(); and about the fact that my program will crash if you enter a character instead of a value.

Not just me. Others pointed it out first and I agreed. And you argued that your program was perfect. When asked "what happens when you input a character?" you responded:

You: The program will crash. You have to fill in a number.
You: I have tested my program already. I solved every single mistake which I have made. The program also takes to account with leap years and with correctionyears.
You: It is a perfect program now. :-D
You: It is. The program will prevent you from entering invalid data.
You: When you enter characters instead of numbers, the program doesn't know what to do with it, so it crashes.

Crashing is an error, not a valid way to prevent invalid data

See the pattern?

You: In some if-statements I am using main(); to restart the program. That is not bad!

More arguing about a bad practice.

I asked WaltP which code I have to use to restart my program is main(); is not good enough, and which code I have to use so my program won't crash if you enter a character instead of a value.

And why should I wish to help after all the above attitude, arguing, telling us we are wrong? What makes you think we'd be interested in helping after all that?

Yes, I can help you with that. I've done it many times on these boards. But you need to lose the I know more than you attitude before that happens.

And you continued:

Lucaci Andrew: All of your souce code is in one function, and that function is the specific starting function of your program - what is wrong with you? Haven't you heard about other functions, classes maybe, structures? This is not Python to just use any function as the starting point of your program, then to recursivelly call it to "restart your program".

You: In C++, it isn't necessary to use different functions in this situation. It is a possibility, but the compiler will still be able to compile the code fine, even if it has only one function. The program, with only one long function, will also run without any problems.

More arguing.

You: Just like you can use "\n" to go to the next line, or "endl". It's exactly the same.

More false information claiming it's true.

You: Note that there are specific items from C++ that work only on some OS. Linux is different from Windows, and if you implement some specific items from Windows, don't expect to work on Linux.

Of course there are different operating systems. Linux is different than Windows, but the program language, C++, should be the same.

But refusing to understand that using something that is Windows-based in the code makes the code not compile on linux!! therefore it is not standard C++.

You: Now, I want to fix the problem that if I enter a character instead of a value, the program will crash. WaltP and deceptikon are refusing to help me. They just say that my program is bad and that I am trolling.

I never said you were trolling.
As I said, lose the attitude, the arrogance, and open your mind to learn the facts, and you'll get help from us. But so far, that hasn't happened.

NathanOliver: That’s not to say you shouldn’t argue a point if you don’t agree but if you are going to, make sure you have some clear examples and/or references to back you up.

Exactly. And I've freely admitted when I've been wrong and someone corrects me.

You: WaltP and Suzie999 aren't helping or giving advises. They are just bashing my program, without telling me which code I have to use to solve the problems I have made.

We offered, but you argued rather than listened.

Against my better judgement I'm posting again after declaring myself out
I'm sorry for the backtrack to members here.

markwiering, help comes in many forms, but when you just say
"tell me the code" you are not even helping yourself, so how
can anyone else help you?

You need to help yourself first, learn how to search for a
question you need an answer to.

Type your question into a search engine and look through the
results.

I'm little more than a beginner myself, so bare that in mind
while reading what I'm advising.

Collect your input from cin() as a string/Char*
Loop through it, and perhaps check each element
with isdigit() function.

If they are all digits then convert the string/char*
to the data type you need to work with, if not then
continue the loop that this routine should be in.

While you are excersising your mind on how to put
that into code, you will learn rapidly that another
piece of advice offered in this thread was xaluable.

That is functions/methods/routines whatever you want to
call them.

Once again, best of luck and keep at it if you truly want
to learn.

commented: well said, nice post... +11
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.