Hello members,
I just started programming and had to work on a certain assignment. The program ought to do different things like verifying age, calculating age etc. So I split it and worked on small parts.
The first part with verifying age is done with no errors. I started working on part 2 which was to calculate the age of the user. I copied the code from notepad, pasted it into the existing code but it showed some errors I don't understand yet. The error stated that in the very last else-statement 'expected primary expression before else and expected ';' before else. What also bothers me is that when I debug it, the program runs the 'part-1' but ends there, while there also is a 'part 2'.
Any guidance would be greatly appreciated. As until now, we only covered the pure 'basics' and the different boolean expressions.
~liz~
Code:
#include <iostream>
#include <windows.h>
using namespace std;
int main ()
{
int PEILJAAR;
PEILJAAR: 2012;
int PEILMAAND;
PEILMAAND: 9;
int PEILDAG;
PEILDAG: 23;
int j, m, d;
int Leeftijd_maandentotaal;
int Leeftijd_jaar;
int Leeftijd_maanden;
//Eerst vragen we de gebruiker om zijn geboortegegevens in te vullen//
cout << "Voer geboortejaar in."<< endl;
cin >> j;
if (j<1912 || j>2002) {
cout << "Te jong/te oud. "<< endl; //We kijken gelijk al of hij qua jaar te jong of te oud is//
Sleep (500);
}
else
{
cout <<"Voer geboortemaand in."<< endl;
cin >> m;
if (m<1 || m>12){
cout <<"Dat kan niet. "<< endl; //We controleren ook gelijk of hij wel een normale maand invult//
Sleep (500);
}
else {
cout <<"Voer geboortedag in. "<<endl;
cin >> d;
/*Nu gaan we met behulp van if-else de gehele datum klopt, samen met de ingevulde datum.
De laatste els if statement controleert het schrikkeljaar voor februari. Zo hebben we alle mogelijke data gecontroleerd*/
if ((d<1 || d>31) && (m==1,3,5,7,8,10,12))
cout <<"Dat kan niet."<< endl;
else if ((d<1 || d>30) && (m==4,6,9,11))
cout <<"Dat kan niet."<< endl;
else if ((j%4!=0)&&(m==2) && (d==29))
cout <<"Dat kan niet."<< endl;
/*this was part 1*/
}
}
/*De leeftijd berekenen we vervolgend met het volgende stuk code. Er zijn 4 verschillende mogelijkheden
, waarvan het programma een uitvoert*/
/*part 2 begins here*/
if ((d<PEILDAG) && (m<PEILMAAND) && (j<PEILJAAR)){
Leeftijd_maandentotaal = ((PEILMAAND-m)+(PEILJAAR-j)*12);
Leeftijd_jaar = (PEILJAAR-j);
Leeftijd_maanden; ((PEILMAAND-m));
cout<<"Jouw leeftijd is "<<Leeftijd_maandentotaal<<" maanden totaal en "<<Leeftijd_jaar<<"jaar en "<<Leeftijd_maanden<<"maanden."<< endl;}
else if ((d>PEILDAG) && (m>PEILMAAND) && (j<PEILJAAR)){
Leeftijd_maandentotaal = (((PEILJAAR-j-1)*12)+(m-PEILMAAND)-1);
Leeftijd_jaar = (PEILJAAR-j-1);
Leeftijd_maanden = (12+(m-PEILMAAND)-1);
cout<<"Jouw leeftijd is "<<Leeftijd_maandentotaal<<" maanden totaal en "<<Leeftijd_jaar<<"jaar en "<<Leeftijd_maanden<<"maanden."<< endl;}
else if ((d<PEILDAG) && (m>PEILMAAND) && (j<PEILJAAR));{
Leeftijd_maandentotaal = (((PEILJAAR-j)*12)+(m-PEILMAAND));
Leeftijd_jaar = (PEILJAAR-j-1);
Leeftijd_maanden = (12+(m-PEILMAAND));
cout<<"Jouw leeftijd is "<<Leeftijd_maandentotaal<<" maanden totaal en "<<Leeftijd_jaar<<"jaar en "<<Leeftijd_maanden<<"maanden."<< endl;}
else if ((d>PEILDAG) && (m<PEILMAAND) && (j<PEILJAAR)){
Leeftijd_maandentotaal = (((PEILJAAR-j)*12)+((m-PEILMAAND)+1));
Leeftijd_jaar = (PEILJAAR-j);
Leeftijd_maanden = ((PEILMAAND-m)-1);
cout<<"Jouw leeftijd is "<<Leeftijd_maandentotaal<<" maanden totaal en "<<Leeftijd_jaar<<"jaar en "<<Leeftijd_maanden<<"maanden."<< endl;}
return 0;
}