I`m really confiused about it pleas help me. I`m a beginner. this program supposed to show your age, by day/week/year. Also the day of the week that u borne.
It shouldn`t work after 150 year. people less than 10 years old and above 100 years are not allow to use it.
what for compiler should I use? I used Devc++ but after upgrading my windows to win10 it`s not work anymore
// progeraam opgaven1
#include <iostream>
#include <string>
#include <string>
usingnamespace std;
constint currentyear = 2015;
int GetDates(int year, int month, int day); //Functionprototype.
int JulianDateNum(int day,int jdn,long intRes1,long intRes2,long intRes3);
int main()
{
int year; //Declare variables
int month;
int day;
int dayOfWeek;
int jdn;
cout << "This progeram was created to find the Birth day and you age "
<< "created by ....." << endl;
//Get input from user
cout << "In wich year did u borned? (yyyy): ";
cin >> year;
//pprogeram should work for 150 years
if (currentyear - year < 0 || currentyear - year > 150) {
cout << "This year is out of range! Please enter a year " << endl;
return 1;
}
// check if user abvoe 10 and under 150 year is
if (currentyear - year < 10){
cout << "This progeram is not for you" << endl;
return 1;
}
if (currentyear - year > 100){
cout << "your are too old for this progeram" << endl;
return 1;
}
//Get the mothn and check it for condition
cout << "in which month did you bornd(1-12)? (mm)" << endl;
cin >> month;
if (month < 1 || month > 12) {
cout << "Invalid data! Please enter a month " << endl;
return 1;
}
if (currentyear - year == 10 && currentmonth - month < 0){
cout << "Come back next year" << endl;
retrun 1;
}
if (currentyear - year == 10 && currentmonth - month > 0){
cout << "Lets sleep,you are too old" << endl;
return 1;
}
// Get Bday and check it for condition
cout << "In wich day did you borned? day (dd): ";
cin >> day;
if ( day < 1 || day > 31){
cout << "Lets check the day agin" << endl;
returne 1;
}
switch (month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if ( day > 31){
cout << "It is not a jok!,bye" << endl;
return 1;
}
break;
case 2:
if (year % 4 == 0){
if (day > 20 ){
cout << "It is not a jok!,bye" << endl;
return 1;
}
}
else{
if ( day > 28){
cout << "It is not a jok!,bye" << endl;
return 1;
}
}
break;
case 4:
case 6:
case 9:
case 11:
if (day > 30){
cout << "It is not a jok!, bye" << endl;
retrun 1;
}
break;
if (currentyear - year == 10 && currentmonth - month == 0 &&
currentday - day < 0){
cout << "wait" << day - currentday << "days and try again" << endl;
return 0;
}
if (currentyear - year == 100 && currentmonth - month == 0
&& currentday - day < 0){
cout << "you just pased the border for progeram " << endl;
return 1;
}
//days between 1-1-1901 and Bdate
difference = ( year - 1901) / 4 + Byear + Bday + mshift; // calculates day of the week
days = day - 1;
if (month > 1){
days = days + 31;
}
if (month > 2){
days = days + 28;
}
if (month > 3){
days = days + 31;
}
if (month > 4){
days = days + 30;
}
if (month > 5){
days = days + 31;
}
if (month > 6){
days = days + 30;
}
if (month > 7){
days = days + 31;
}
if (month > 8){
days = days + 31;
}
if (month > 9){
days = days + 30;
}
if (month > 10){
days = days + 31;
}
if (month > 11){
days = days + 30;
}
// calculate days
days = days + (( year - 1901) * 365) + ((year - 1900) / 4));
//calculate months
week = ((1 + days) % 7) + 1;
cout << "Untill today you lived for :" << days << endl;
cout << "Untill today you lived for :" << weeks << endl;
//day of week
if (dayOfWeek == 0){
cout << "The day of your Birth is : Mo" << endl;
break;
return 0;
}
elseif (dayOfWeek == 1){
cout << "The day of your Birth is :Tu" << endl;
break;
return 0;
}
elseif (dayOfWeek == 2){
cout << "The day of your Birth is :We" << endl;
break;
return 0;
}
elseif (dayOfWeek == 3){
cout << "The day of your Birth is :Th" << endl;
break;
return 0;
}
elseif (dayOfWeek == 4){
cout << "The day of your Birth is :Fr" << endl;
break;
return 0;
}
elseif (dayOfWeek == 5){
cout << "Sa" << endl;
break;
return 0;
}
elseif (dayOfWeek == 6){
cout << "Su" << endl;
break;
return 0;
}
return 0; // Terminates program.
}
In function 'int main()':
44:38: error: 'currentmonth' was not declared in this scope
46:10: error: 'retrun' was not declared in this scope
48:38: error: 'currentmonth' was not declared in this scope
57:9: error: 'returne' was not declared in this scope
92:20: error: 'retrun' was not declared in this scope
95:43: error: 'currentmonth' was not declared in this scope
96:11: error: 'currentday' was not declared in this scope
100:39: error: 'currentmonth' was not declared in this scope
101:13: error: 'currentday' was not declared in this scope
107:9: error: 'difference' was not declared in this scope
107:43: error: 'Byear' was not declared in this scope
107:51: error: 'Bday' was not declared in this scope
107:58: error: 'mshift' was not declared in this scope
108:6: error: 'days' was not declared in this scope
145:6: error: 'week' was not declared in this scope
147:48: error: 'weeks' was not declared in this scope
17:9: warning: unused variable 'jdn' [-Wunused-variable]
185:1: error: expected '}' at end of input
OK you have all these errors to fix. They are why it won't run. Start at the first error at the top of the list, fix it, run again, get the error list from that run and repeat.
All the best. If you have any problems let us know. We help but generally don't fix without you trying first.
The error list says at line 44 you haven't declared a variable called current month. All you have to do is declare it yaser. You did it with other variables ...
You can grab the current unix timestamp from time(0); in the <time.h> header
If you want to pull out the current date, you can use the localtime() function such as this function to get a month from a timestamp (which you receive from the time(0) function)
1 2 3 4 5 6 7
int getMonth(time_t timeval){
struct tm * timeinfo;
timeinfo = localtime(&timeval);
if (timeinfo!=NULL)
return timeinfo->tm_mon + 1;
return -1;
}
@kemort : I need a current date source to declare currentday, currentmonth and currentyear and I don`t have it, I try several codes but no success. I shouldn`t ask it from user.
@wizebin: if I use this codes how can I find currentdate? its only for time!
// progeraam opgaven1
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
usingnamespace std;
int main()
{
constint currentyear = 2015;
int GetDates(int year, int month, int day); //Functionprototype.
int year; //Declare variables
int month;
int day;
int dayOfWeek;
int jdn;
int currentday;
int currentmonth;
int currentyear;
int difference
// current date
tm s;
time_t t;
time (&t);
s = * localtime (&t);
currentday = s.tm_mday;
currentmonth = s.tm_mon + 1;
currentyear = s.tm_year + 1900;
cout << "This progeram was created to find the Birth day and you age "
<< "created by Yaser kazemi (s1714341)" << endl;
//Get input from user
cout << "In wich year did u borned? (yyyy): ";
cin >> year;
//pprogeram should work for 150 years
if (currentyear - year < 0 || currentyear - year > 150) {
cout << "This year is out of range! Please enter a year " << endl;
return 1;
}
// check if user abvoe 10 and under 150 year is
if (currentyear - year < 10){
cout << "This progeram is not for you" << endl;
return 1;
}
if (currentyear - year > 100){
cout << "your are too old for this progeram" << endl;
return 1;
}
//Get the mothn and check it for condition
cout << "in which month did you bornd(1-12)? (mm)" << endl;
cin >> month;
if (month < 1 || month > 12) {
cout << "Invalid data! Please enter a month " << endl;
return 1;
}
if (currentyear - year == 10 && currentmonth - month < 0){
cout << "Come back next year" << endl;
return 1;
}
if (currentyear - year == 10 && currentmonth - month > 0){
cout << "Lets sleep,you are too old" << endl;
return 1;
}
// Get Bday and check it for condition
cout << "In wich day did you borned? day (dd): ";
cin >> day;
if ( day < 1 || day > 31){
cout << "Lets check the day agin" << endl;
return 1;
}
switch (month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if ( day > 31){
cout << "It is not a jok!,bye" << endl;
return 1;
}
break;
case 2:
if (year % 4 == 0){
if (day > 20 ){
cout << "It is not a jok!,bye" << endl;
return 1;
}
}
else{
if ( day > 28){
cout << "It is not a jok!,bye" << endl;
return 1;
}
}
break;
case 4:
case 6:
case 9:
case 11:
if (day > 30){
cout << "It is not a jok!, bye" << endl;
return 1;
}
break;
}
if (currentyear - year == 10 && currentmonth - month == 0 &&
currentday - day < 0){
cout << "wait" << day - currentday << "days and try again" << endl;
return 0;
}
if (currentyear - year == 100 && currentmonth - month == 0
&& currentday - day < 0){
cout << "you just pased the border for progeram " << endl;
return 1;
}
//days between 1-1-1901 and Bdate
difference = ( year - 1901) / 4 + year + day + mshift; // calculates day of the week
day = day - 1;
if (month > 1){
day = day + 31;
}
if (month > 2){
day = day + 28;
}
if (month > 3){
day = day + 31;
}
if (month > 4){
day = day + 30;
}
if (month > 5){
day = day + 31;
}
if (month > 6){
day = day + 30;
}
if (month > 7){
day = day + 31;
}
if (month > 8){
day = day + 31;
}
if (month > 9){
day = day + 30;
}
if (month > 10){
day = day + 31;
}
if (month > 11){
day = day + 30;
}
// calculate days
day = day + (( year - 1901) * 365) + ((year - 1900) / 4));
//calculate months
week = ((1 + day) % 7) + 1;
cout << "Untill today you lived for :" << day << endl;
cout << "Untill today you lived for :" << week << endl;
//day of week
if (dayOfWeek == 0){
cout << "The day of your Birth is : Mo" << endl;
return 0;
}
elseif (dayOfWeek == 1){
cout << "The day of your Birth is :Tu" << endl;
return 0;
}
elseif (dayOfWeek == 2){
cout << "The day of your Birth is :We" << endl;
return 0;
}
elseif (dayOfWeek == 3){
cout << "The day of your Birth is :Th" << endl;
return 0;
}
elseif (dayOfWeek == 4){
cout << "The day of your Birth is :Fr" << endl;
return 0;
}
elseif (dayOfWeek == 5){
cout << "Sa" << endl;
return 0;
}
elseif (dayOfWeek == 6){
cout << "Su" << endl;
return 0;
}
return 0;
}
I'm a beginner too but noticed some obvious errors.
missing a semicolon(;) on line 20.
declared a const int on line 9 (currentyear) and then you've tried to assign a different value to it in line 19.
mshift is undefined at 119
week is undefined at 157