#include <iostream>
#include <fstream>
#include <windows.h>
#include <ctime>
#include <string>
#include <iomanip>

using namespace std;

enum ConsoleColor {Black, Blue, Green, Cyan, Red, Magenta, Brown, LightGray, DarkGray, LightBlue, 
LightGreen, LightCyan, LightRed, LightMagenta, Yellow, White };


void line(void);
const int Start=1900;
void write_Data();
void Read_Data();


void SetColor(int text, int background=Black)
{
     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
     SetConsoleTextAttribute(hStdOut, (WORD)((background << 4) | text));
}

struct user
{
    string Name;
    string Content;
    string Venue;
    int    tahun;
    int    bulan;
    int    hari;
    int    hour;
    int    minute;
};

int main()
{

int djan=31, dfeb=28, dmar=31, dapr=30, dmay=31, djun=30, 
    djul=31, daug=31, dsep=30, doct=31, dnov=30, ddec=31;
int year, month, diem, k=0, days=0,  n=0, m=0, tag=0,z=0;
int count=0, index=0;
char choice;
fstream taskfile;

    user task[1000];

   time_t now = time(0);
   tm *ltm = localtime(&now);

   year=1900 + ltm->tm_year;
for (int i=Start; i<year; i++)
{
    n++;
    if (i%4==0 && i%100!=0 || i%400==0)
    {
        days+=366;
    }
    else
        days+=365;
}

month=1 + ltm->tm_mon;


diem=ltm->tm_mday;


system("cls");

error_choice:

line();
SetColor(Yellow);
cout<<"\t\t\t\t"<<year<<"\n\n";
SetColor(White);
line();
SetColor(LightCyan);
switch(month)
{
case 1: cout<<"\t\t\t\tJanuary\n\n";
    m=0;
    tag=djan;
    break;
case 2: cout<<"\t\t\t\tFebruary\n\n";
    m=djan;
    (year%4==0 && year%100!=0 || year%400==0) ? tag=dfeb+1 :tag=dfeb;
    break;
case 3: cout<<"\t\t\t\tMarch\n\n";
    m=djan+dfeb;
    tag=dmar;
    break;
case 4: cout<<"\t\t\t\tApril\n\n";
    m=djan+dfeb+dmar;
    tag=dapr;
    break;
case 5: cout<<"\t\t\t\tMay\n\n";
    m=djan+dfeb+dmar+dapr;
    tag=dmay;
    break;
case 6: cout<<"\t\t\t\tJune\n\n";
    m=djan+dfeb+dmar+dapr+dmay;
    tag=djun;
    break;
case 7: cout<<"\t\t\t\tJuly\n\n";
    m=djan+dfeb+dmar+dapr+dmay+djun;
    tag=djul;
    break;
case 8: cout<<"\t\t\t\tAugust\n\n";
    m=djan+dfeb+dmar+dapr+dmay+djun+djul;
    tag=daug;
    break;
case 9: cout<<"\t\t\t\tSeptember\n\n";
    m=djan+dfeb+dmar+dapr+dmay+djun+djul+daug;
    tag=dsep;
    break;
case 10: cout<<"\t\t\t\tOctober\n\n";
    m=djan+dfeb+dmar+dapr+dmay+djun+djul+daug+dsep;
    tag=doct;
    break;
case 11: cout<<"\t\t\t\tNovember\n\n";
    m=djan+dfeb+dmar+dapr+dmay+djun+djul+daug+dsep+doct;
    tag=dnov;
    break;
case 12: cout<<"\t\t\t\tDecember\n\n";
    m=djan+dfeb+dmar+dapr+dmay+djun+djul+daug+dsep+doct+dnov;
    tag=ddec;
    break;
default: cout<<"\a\nInput error! Bye!\n";
    return 0;
    break;
}
SetColor(White);
(year%4==0 && year%100!=0 || year%400==0) ? m++ : m;    
days+=m;
z=(days+diem-1)%7;
k=days%7;
line();
cout<<"\n\tMon\tTue\tWed\tThu\tFri";
SetColor(LightRed);
cout<<"\tSat\tSun\n\n";
SetColor(White);
line();
cout<<"\n\t";
for (int j=0; j<k; j++)
    cout<<"\t";
for (int u=1; u<=tag; u++)
{
    if ((u+k)%7==0||(u+k+1)%7==0)
        SetColor(LightRed);
    else if (u==diem)
        SetColor(LightGreen);
    cout<<u<<"\t";
    SetColor(White);
    if ((u+k)%7==0)
        cout<<"\n\n\t";
}
cout<<"\n\n";
cout<<"\n\n\t"<<diem<<"."<<month<<"."<<year<<" - it is ";
switch(z)
{
case 0: cout<<"Monday\n";
    break;
case 1: cout<<"Tuesday\n";
    break;
case 2: cout<<"Wednesday\n";
    break;
case 3: cout<<"Thursday\n";
    break;
case 4: cout<<"Friday\n";
    break;
case 5: cout<<"Saturday\n";
    break;
case 6: cout<<"Sunday\n";
    break;
}
SetColor(LightGreen);
cout << "\n\tTime: "<< ltm->tm_hour << ":";
cout << ltm->tm_min << ":";
cout << ltm->tm_sec << endl;

SetColor(LightGray);
cout<<endl;
do
{
cout<<"Do you want to continue?"<<endl;
cout<<"1.Make an appointment"<<endl;
cout<<"2.Exit"<<endl;
cin>>choice;
}while(choice==0||choice==1);


switch(choice)
{
case'1':
    {

        system ("CLS");
        taskfile.open("task.dat",ios::out| ios::binary | ios::app);

        cout<<"Please enter your name"<<endl;
        **getline(cin,task[count].Name);**
        cout<<"Please enter the date(dd mm yy)"<<endl;
        cin>>task[count].hari;
        cin>>task[count].bulan;
        cin>>task[count].tahun;
        cout<<"Please enter the time(hh mm)"<<endl;
        cin>>task[count].hour;
        cin>>task[count].minute;
        cout<<"Please enter the contents"<<endl;
        cin>>task[count].Content;
        cout<<"Please enter the venue"<<endl;
        cin>>task[count].Venue;
        count++;
        count=index;

        taskfile<<task[count].Name;
        taskfile<<task[count].hari;
        taskfile<<task[count].bulan;
        taskfile<<task[count].tahun;
        taskfile<<task[count].hour;
        taskfile<<task[count].minute;
        taskfile<<task[count].Content;
        taskfile<<task[count].Venue;

        taskfile.close();

        system("CLS");
        cout<<"Your note had been took down"<<endl;



        system("pause");
        goto error_choice;
        break;
    }
case '2':
    {
        write_Data();
        system ("CLS");

        cout<<"Welcome again\n\n\n"<<endl;

        system ("pause");
        return 0;
        break;
    }
default:
    {
        system ("CLS");
        goto error_choice;
    }
}

system ("pause");

}

void line(void)
{
    SetColor(Blue);
cout<<"\t";
for (int i=0; i<51; i++)
{
    cout<<'~';
}
SetColor(White);
cout<<"\n";
}

void write_Data()
{
    user task[1000];
    fstream taskfile;
    int index=0;
    int size=0;

    taskfile.open("task.dat",ios::out| ios::binary | ios::app);

    for (int count=0; count<index; count++)
    {

        task[count].Name;
        task[count].tahun;
        task[count].bulan;
        task[count].hari;
        task[count].Content;
        task[count].Venue;
        task[count].hour;
        task[count].minute;

        taskfile.write (reinterpret_cast <char*> (&task), size);
    }

    taskfile.close();
}

void Read_Data()
{
    user task[1000];
    fstream taskfile;
    int count=0;
    int size=0;

    taskfile.open("task.dat", ios::in | ios::binary);

    taskfile.read(reinterpret_cast <char*> (&task), size);

    while(!taskfile.eof())
    {

        task[count].Name;
        task[count].tahun;
        task[count].bulan;
        task[count].hari;
        task[count].Content;
        task[count].Venue;
        task[count].hour;
        task[count].minute;
        count++;
        taskfile.read(reinterpret_cast <char*> (&task), size);
    }

    taskfile.close();
    return;
}

Recommended Answers

All 8 Replies

You are going to have to narrow down the problem a bit more for us -- where is the problem? Don't expect us to wade through hundreds of lines of code to find it ourselves. Ain't going to happen.

line 204...sry

my input line 204 is not functioning...the programme skip to next command

give this article a look.

ty,nathanoliver....but still the article is too hard for me to understand

When you enter a numeric type such as integer or float you have to press the <Enter> key, which is represented in the program as '\n'. Then cin processes the keystrokes one at a time and stores valid numbers in the numeric data. It stops converting when cin encounters the first non-valid character, such as that enter key '\n' and returns control to your program. That leaves the keyboard buffer in an unknown and unpredictable state, so before continuing the program needs to flush out all remaining keys.

In c++ there is an easy way to flush the keyboard buffer, which is explained in detail in that link that Nathan prosted. Yes there is some complicated theory in Narue's article, but the only part you need is at the very beginning

#include <ios>
#include <istream>
#include <limits>

void ignore_line ( std::istream& in )
{
  in.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );
}

With the above, just call ignore_line() after the calling cin that gets an integer or float. For example:

cout<<"Please enter the time(hh mm)"<<endl;
        cin>>task[count].hour;
        cin>>task[count].minute;
        ignore_line(cin); // <<<<< Flush keyboard buffer

in.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );
this line has syntax error ')'

what error message did you get? Did you add the includes that I posted? what compiler are you using?

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.