My programm doesn't work

Lotdog

Member
Aug 13, 2004
50
0
0
//////////////////////////////////////////////////////////////////////////////////////////////
// console gregorian calender app.
// (c) stoned coder 2001
// uses zeller's algorithm for finding the day for the date
//////////////////////////////////////////////////////////////////////////////////////////////
// details of algorithm are :-
//
// [x] = floor (x)
//
// f=k+[((13*m)-1)/5]+d+[d/4]+[c/4]-(2*c)
//
// where k=day of the month
// m=month number march=1 jan=11 feb=12 etc.
// d=last two digits of year.... if m=1 or m=2 d=d-1 (jan,feb treated as previous
//year)
// c=first two digits of year i.e. number of centuries.
//
// once we have f we divide by 7 and take remainder.If negative add 7. remainder = day of the week
// 0=sunday 1=monday 6=saturday etc.
//////////////////////////////////////////////////////////////////////////////////////////////
// includes
#include <iostream>
#include <iomanip>
#include <cmath>
#include <windows.h>
#include <cstdlib>
// using statements
using namespace std;
// function prototypes
void clrscr();
void gotoxy(int,int);
// classes
class calender
{
public:
calender(int d=1,int m=1,int y=2001); //defaults to 1/1/2001 (uk format dd/mm/yy)
virtual ~calender() {} // do nothing destructor virtual in case of use of inheritance
void printcalender();

private:
bool isleapyear(); // returns true if year is leap
int checkday(int); // checks legality of date
int whatdayisfirstofmonth(); // returns 0 to 6 sunday to saturday
int howmanydays(); // returns number of days in month
int day;
int month;
int year;
};
//////////////////////////////////////////////////////////////////////////////////////////////
// constructor
//
// checks validity of date and sets members
//
//////////////////////////////////////////////////////////////////////////////////////////////
calender::calender(int d,int m,int y)
{

if (y<1582) // church accepted gregorian calender in 1582
{
cout<<endl<<"The year "<<y<<" is before the gregorian calender was accepted by the church."
<<"Setting to 2001."<<endl;
year=2001; // invalid year so set to 2001
}
else
{
year=y; // y is valid so use it to set year
}
if ((m>=1) &amp;&amp; (m<=12)) // check month between 1 and 12
{
month=m; // if it is set month
}

else
{
cout<<endl<<"The month "<<m<<" is invalid. Setting to month 1"<<endl;
month=1;
}
day=checkday(d); // validate the day
}
//////////////////////////////////////////////////////////////////////////////////////////////
//
// isleapyear()
//
// checks whether year is a leap year in the gregorian calender
// a year is leap if it is divisable by four but not if divisible by 100
// unless it is divisible by 400
//
// returns true if leap and false if not
//
//////////////////////////////////////////////////////////////////////////////////////////////
bool calender::isleapyear()
{
if ((year@0==0) || ((year %4==0) &amp;&amp; (year.0 !=0)))
{
return true; // its a leap year
}

else
{
return false; // its not a leap year
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
//
// checkday(int)
//
// checks day is legal for month
//
// in:- day to be tested
//
// returns day if legal and 1 if not legal
//
//////////////////////////////////////////////////////////////////////////////////////////////
int calender::checkday(int testday)
{

if ((testday>0) &amp;&amp; (testday<= howmanydays()))
{
return testday; // day is valid for month
}
cout<<endl<<"Invalid day entered "<<testday<<"/"<<month<<"/"<<year
<<". Setting to the first of the month."<<endl;
return 1; // hopefully wont get here but if invalid day entered day is set to 1
}
//////////////////////////////////////////////////////////////////////////////////////////////
//
// int howmanydays()
//
// returns number of days in month
//
//////////////////////////////////////////////////////////////////////////////////////////////
int calender::howmanydays()
{
if((month==2)&amp;&amp; isleapyear())
{
return 29; // feb has 29 days in a leap year
}
static const int daysinmonth[12]={31,28,31,30,31,30,31,31,30,31,30,31};
return daysinmonth[month-1];
}
//////////////////////////////////////////////////////////////////////////////////////////////
//
// int whatdayisfirstofmonth()
//
// uses zeller's algorithm to find out what day the first of the month falls on falls on.
//
// returns 0 to 6 corresponding to sunday to saturday.
//
//////////////////////////////////////////////////////////////////////////////////////////////
int calender::whatdayisfirstofmonth()
{
int c=year/100; // # of centuries
int d=year.0; // # of years through century
int m=(month+10).; // # of month march is 1,feb is 12
int k=1; // set the day part to 1 so we get back the day for first of month
if ((month==1)||(month==2))// treat jan and feb as if they were in previous year
{
if (d==0) // if d is 0 then to go back a year d becomes 99 and c become c-1
{
d=99;
c-=1;
}
else
{
d-=1; // jan and feb are treated as previous year
}
}
float g=(k + (floor(((13*m)-1)/5)) + d + (floor(d/4)) + (floor(c/4)) - (2*c));
int f=static_cast<int>(g)%7; // cast result of algorithm to int to take modulus
if (f<0) // if negative add 7
{
f+=7;
}
return f; // returns 0 to 6 corresponding to sunday to saturday
}
//////////////////////////////////////////////////////////////////////////////////////////////
//
// void printcalender()
//
// prints the calender for the entered date
//
//////////////////////////////////////////////////////////////////////////////////////////////
void calender:rintcalender()
{
clrscr();
cout<<"Date entered was :- "<<day<<"/"<<month<<"/"<<year<<endl;
cout<<endl<<setw(8)<<"SUNDAY"<<setw(8)<<"MONDAY"<<setw(9)<<"TUESDAY"<<setw(11)<<"WEDNESDAY"<<setw(10)
<<"THURSDAY"<<setw(8)<<"FRIDAY"<<setw(10)<<"SATURDAY"<<endl;
int startday=whatdayisfirstofmonth();
int endday=howmanydays();
for (int i=0;i<startday;i++)
{
if (i==0)
{
gotoxy(4,4);
cout<<"-";
}
if (i==1)
{
gotoxy(12,4);
cout<<"-";
}
if (i==2)
{
gotoxy(21,4);
cout<<"-";
}
if (i==3)
{
gotoxy(31,4);
cout<<"-";
}
if (i==4)
{
gotoxy(42,4);
cout<<"-";
}
if (i==5)
{
gotoxy(50,4);
cout<<"-";
}
} // end of for loop


int rows=4;
int count=1;
for(int j=startday;j<(startday+endday);j++)
{
if(j%7==0)
{
rows+=2;
gotoxy(4,rows);
}
if(j%7==1) gotoxy(12,rows);
if(j%7==2) gotoxy(21,rows);
if(j%7==3) gotoxy(31,rows);
if(j%7==4) gotoxy(42,rows);
if(j%7==5) gotoxy(50,rows);
if(j%7==6) gotoxy(60,rows);
if(count==day) // set text to bright red if count is the day entered
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
}
else
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN);
}
cout<<count;
count ++;
} // end of for loop
cout<<endl<<endl<<endl;
}
//////////////////////////////////////////////////////////////////////////////////////////////
//
// void clrscr()
//
// clears the console window
//
// Thanks go to sunlight @ cprogramming.com
//
//////////////////////////////////////////////////////////////////////////////////////////////
void clrscr()
{
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &amp;csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &amp;cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &amp;csbi);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &amp;cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
}
//////////////////////////////////////////////////////////////////////////////////////////////
//
// void gotoxy(int x,int y)
//
// moves cursor to x,y in windows console
//
//////////////////////////////////////////////////////////////////////////////////////////////
void gotoxy(int x, int y)
{
COORD point;
point.X = x; point.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),point);
}
//////////////////////////////////////////////////////////////////////////////////////////////
//
// int main()
//
// entry point for program
//
// returns 0 back to the OS
//
//////////////////////////////////////////////////////////////////////////////////////////////
int main()
{

while (1)
{
clrscr();
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN);
cout<<"Welcome to the gregorian calender calculator. v.1.00"<<endl<<endl
<<"Use UK format.... day/month/full year. Use the '/' char to delimit your entry..."
<<endl<<endl;
cout<<"Please enter the date you would like to see the calender for :- ";
char input_day[4];
char input_month[4];
char input_year[6];
cin.getline(input_day,3,'/'); // get the input as strings
cin.getline(input_month,3,'/');
cin.getline(input_year,5,'\n');
cout<<endl;
int d=atoi(input_day); // convert input to integer
int m=atoi(input_month);
int y=atoi(input_year);
calender date(d,m,y); // instantiate the calender object
system("PAUSE"); // wait for a keypress
date.printcalender(); // print the calender
cout<<"Another calender (Y/N) ? ";
char input[5];
cin.getline(input,4);
if ((input[0]=='N') || (input[0]=='n'))
{
break; // drop out of while loop
}
} // end of while loop

return 0;
}

 

Armitage

Banned
Feb 23, 2001
8,086
0
0
A few suggestions:

- Use the "attach code" option so your code retains the proper formatting and is more readable.
- Narrow down your problem. Most people aren't going to bother wading through a big chunk of code and the simple statement "My programm doesn't work".
 

UCJefe

Senior member
Jan 27, 2000
302
0
0
lol. You're going to have to give us a little bit more direction than just "My program doesn't work". I could just imagine people coming to me at work, saying "it doesn't work" and handing me several pages of source code. Anyway, give use some more direction and I'm sure one of the very talented people here will be able to help.

By the way, if anybody solves the OP's problem without more information, you have way too much time on your hands.
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Quick look shows code that I can not comprehend ???
bool calender::isleapyear()
{
if ((year@0==0) || ((year %4==0) &amp;&amp; (year.0 !=0)))

year is defined as an integer.
two of the references to year do not make sense.
 

Lotdog

Member
Aug 13, 2004
50
0
0
Thanks for the tips! I managed to solve the problem, errors were dumb and i can't understand how I didn't saw them earlier!
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |