about reverse date(the 1st one is a wrong question)

This is a discussion on about reverse date(the 1st one is a wrong question) within the C++ Programming forums, part of the General Programming Boards category; i want to input a date and display in this format: 08 march, 2002. and also display error massage if ...

  1. #1
    Unregistered
    Guest

    Smile about reverse date(the 1st one is a wrong question)

    i want to input a date and display in this format: 08 march, 2002. and also display error massage if date is out of range. so i use function printdate().i've tried this program and haven't finished yet...so pleasee tell me the mistake and what should i do next...thank u for you attention#include<iostream.h>
    #include<stdio.h>
    void printdate();
    int main()
    {
    int dd,mm,yy;
    enum month {january=1;february,march,april,may,june,july,augu stus,september,october,november,december};
    cout<<"input a date";
    cin>>dd;
    cout<<endl;
    cout<<"input the day:";
    cin>>mm;
    cout<<endl;
    cout<<"input the month:";
    cin>>yy;
    cout<<endl;
    cout<<"input the year:";
    getchar();
    }
    int printdate(int x, int y, int z)
    {
    if(mm>12)
    cout<<"check the date again";
    else

  2. #2
    Unregistered
    Guest
    #include<stdio.h>
    #include <iostream.h>//note addition to post.

    void printdate(int, int, int); //note changes from post

    int main()
    {
    int dd,mm = 20, yy; //note initialization of mm to an invalid value

    //do you really need this?
    enum month {january=1;february,march,april,may,june,july,augu
    stus,september,october,november,december};

    //note how request for input is now before appropriate variables
    cout<<"input a date";
    cin>>dd;
    cout<<endl;


    while(mm > 12 || mm < 1)
    {
    cout<<"input the number of the month with jan = 1, etc. :" << endl;
    cin >> mm;
    }
    cout << endl;

    cout << "input the year:";
    cin >> yy;
    cout << endl;

    //note call to function, passing "valid" user input.
    print(dd, mm, yy);

    getchar();

    return 0; //note addition to post
    }


    int printdate(int x, int y, int z)
    {
    //print out in whatever pattern you want using numbers
    cout << x << '-' << y << '-' << z;
    cout << y << '-' << x << '-' << z;

    //make it fancier by changing numerical value for month into words
    //really don't need the enum type at all for this.
    switch(y)
    {
    case 1:
    cout << "january ";
    break;
    case 2:
    cout << "feb ";
    break;
    .
    .
    .
    default:
    cout << "program error. sorry." << endl;
    }
    cout << x << ', ' << z;

    cout << "no applause please, just send money." << endl;
    cout << "just kidding." << endl;
    }

    ------------------------------------------------

    if you really want to use the enum type you could do something like this:

    //declare an instance of type month, just like you would any
    //other type
    month Month;

    cout << "january, february, march, april, may, june, july, august, september, october, november, december" << endl;


    cout << "type in name of month exactly as it appears in the list above" << endl;
    cin >> Month;

    cout << Month; //will display numeric value for Month

    //one way to use Month to get written version of month displayed
    switch (Month)
    {
    case january:
    cout << "january << endl;
    break;
    //etc.

    enum types are really integer types but given a "readable" name. I'm not sure how to validated input for enums, or what happens if user enters or programmer uses an out of range/invalid value for an enum type.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I'm not ask for ENTIRE program, only 1 Question !
    By Th3-SeA in forum C Programming
    Replies: 10
    Last Post: 10-01-2003, 01:33 PM
  2. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  3. Reverse() question?
    By correlcj in forum C++ Programming
    Replies: 9
    Last Post: 08-06-2002, 07:02 PM
  4. what does this warningmean???
    By kreyes in forum C Programming
    Replies: 5
    Last Post: 03-04-2002, 07:53 AM
  5. Why did I get this question wrong?
    By DISGUISED in forum C++ Programming
    Replies: 6
    Last Post: 01-31-2002, 04:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21