Twigz's Profile User Rating: -----

Reputation: 2 Apprentice
Group:
Active Members
Active Posts:
76 (0.06 per day)
Joined:
11-July 11
Profile Views:
1,309
Last Active:
User is offline Dec 18 2014 10:59 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   Twigz has not set their status

Posts I've Made

  1. In Topic: About OOP ( need advice )

    Posted 18 Dec 2014

    Ahh ok then Thank you for the advice guys. I actually bought 2 books.
    - Jumping into C++, Alex Allain
    - C++ Primer 5th Edition,
  2. In Topic: Help reading records from file in c

    Posted 22 Nov 2014

    Yes i do, The functions that i have are what was given to me in the Assignment. I can't adjust them and i have to use them. i have them there but i haven't started doing anything with them as yet.

    And yes i do.
  3. In Topic: Help reading records from file in c

    Posted 22 Nov 2014

    hey thank you, but i'm not sure how i'll fix these warnings.

    Quote

    main.c|58|warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘char (*)[21]’ [-Wformat=]|
    main.c|58|warning: format ‘%s’ expects argument of type ‘char *’, but argument 5 has type ‘char (*)[21]’ [-Wformat=]|
  4. In Topic: Help reading records from file in c

    Posted 22 Nov 2014

    sorry, i just edited it in
  5. In Topic: A little help with my assignment

    Posted 4 Oct 2014

    Well guys this is what i've done so far.

    #include <stdio.h>
    
    int ismonth(int month);
    int isday(int day);
    int isyear(int year);
    int ishour(int hour);
    int isminute(int minute);
    int isreturndatevalid ( int rentMonth, int rentDay, int rentYear, int returnMonth, int returnDay, int returnYear, int currentMonth );
    int isreturntimevalid ( int rentMonth, int rentDay, int rentYear, int returnMonth, int returnDay, int returnYear, int rentHour, int rentMinute, int returnHour, int returnMinute );
    int isLeapYear ( int rentYear );
    int durationhours( int rentHour, int returnHour, int rentMinute, int returnMinute, int rentDay, int returnDay, int currentMonth );
    int durationminutes( int rentHour, int returnHour, int rentMinute, int returnMinute, int rentDay, int returnDay, int currentMonth );
    void getPrice( int rentHourT, int rentMinuteT, int valid );
    
    int main()
    {
        printf("\nBig Bike Company Bike Rental System\n");
        printf("===================================\n");
    
        int rentMonth, rentDay, rentYear;
        printf("Enter the date the bike was rented out [mm/dd/yyyy] - ");
        scanf("%d/%d/%d", &rentMonth, &rentDay, &rentYear);
    
        int rentHour, rentMinute;
        printf("Enter the time the bike was rented out [hh:mm] -  ");
        scanf("%d:%d",  &rentHour, &rentMinute);
    
        int returnMonth, returnDay, returnYear;
        printf("\nEnter the date the bike was returned [mm/dd/yyyy] - ");
        scanf("%d/%d/%d", &returnMonth, &returnDay, &returnYear);
    
        int returnHour, returnMinute;
        printf("Enter the time the bike was returned [hh:mm] - ");
        scanf("%d:%d", &returnHour, &returnMinute);
    
        if( !ismonth(rentMonth) || !ismonth(returnMonth))
            printf("\nerror with months\n");
    
        if( !isday(rentDay) || !isday(returnDay))
            printf("\nerror with days\n");
    
        if( !isyear(rentYear) || !isyear(returnYear))
            printf("\nerror with years\n");
    
        if( !ishour(rentHour) || !ishour(returnHour))
            printf("\nerror with hours\n");
    
        if( !isminute(rentMinute) || !isminute(returnMinute))
            printf("\nerror with minutes\n");
    
        enum MONTHS{JAN = 1,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC};
    
        int currentMonth = 0;
        int rentHourT = 0;
        int rentMinuteT = 0;
    
        if ( rentMonth == JAN)
            currentMonth = 31;
        else if ( rentMonth == FEB)
            if ( isLeapYear ( rentYear ))
                currentMonth = 29;
            else
                currentMonth = 28;
        else if ( rentMonth == MAR)
            currentMonth = 31;
        else if ( rentMonth == APR)
            currentMonth = 30;
        else if ( rentMonth == MAY)
            currentMonth = 31;
        else if ( rentMonth == JUN)
            currentMonth = 30;
        else if ( rentMonth == JUL)
            currentMonth = 31;
        else if ( rentMonth == AUG)
            currentMonth = 31;
        else if ( rentMonth == SEP)
            currentMonth = 30;
        else if ( rentMonth == OCT)
            currentMonth = 31;
        else if ( rentMonth == NOV)
            currentMonth = 30;
        else if ( rentMonth == DEC)
            currentMonth = 31;
    
        int valid;
    
        if ( !isreturndatevalid ( rentMonth, rentDay, rentYear, returnMonth, returnDay, returnYear, currentMonth ) )
            valid = 0;
        if ( !isreturntimevalid ( rentMonth, rentDay, rentYear, returnMonth, returnDay, returnYear, rentHour, rentMinute, returnHour, returnMinute ) )
            valid = 0;
    
        rentHourT = durationhours( rentHour, returnHour, rentMinute, returnMinute, rentDay, returnDay, currentMonth );
        rentMinuteT = durationminutes( rentHour, returnHour, rentMinute, returnMinute, rentDay, returnDay, currentMonth );
    
        if(valid)
            printf("\nDuration of Rental: %d hours, %d minutes\n", rentHourT, rentMinuteT);
        else
            printf("\nDuration of Rental: ERROR\n");
    
        getPrice( rentHourT, rentMinuteT, valid );
    
       `return 0;
    }
    
    int ismonth(int month)
    {
        int valid = 1;
    
        if( month < 1 || month > 12)
            valid = 0;
    
        return valid;
    }
    
    int isday(int day)
    {
        int valid = 1;
    
        if( day < 1 || day > 31)
            valid = 0;
    
        return valid;
    }
    
    int isyear(int year)
    {
        int valid = 1;
    
        if( year < 0)
            valid = 0;
    
        return valid;
    }
    
    int ishour(int hour)
    {
        int valid = 1;
    
        if( hour < 0 || hour > 23)
            valid = 0;
        return valid;
    }
    
    int isminute(int minute)
    {
        int valid = 1;
    
        if( minute < 0 || minute > 59)
            valid = 0;
    
        return valid;
    }
    
    int isreturndatevalid ( int rentMonth, int rentDay, int rentYear, int returnMonth, int returnDay, int returnYear, int currentMonth )
    {
        int valid = 1;
    
        if ( rentYear == returnYear && rentMonth > returnMonth )
        {
            printf("\nerror with return month!!\n");
            valid = 0;
        }
    
        if ( (rentYear == returnYear) && rentMonth > returnMonth)
        {
            printf("\nInvalid return Month!!\n");
            valid = 0;
        }
    
        if ( (rentYear == returnYear) && (rentMonth == returnMonth) && rentDay > returnDay )
        {
            printf("\nerror with return day!!\n");
            valid = 0;
        }
    
        if ( ((rentMonth == returnMonth) && ( rentYear == returnYear )) && rentDay > returnDay )
        {
            printf("\nInvalid return Day!!\n");
            valid = 0;
        }
    
        if( rentDay > currentMonth )
        {
            printf("\nInvalid rent Day!!\n");
            valid = 0;
        }
    
        if( returnDay > currentMonth)
        {
            printf("\nInvalid return Day!!\n");
            valid = 0;
        }
    
        if ( rentYear > returnYear )
        {
            printf("\nerror with return year!!\n");
            valid = 0;
        }
    
        if( rentYear > returnYear )
        {
            printf("\nerror with return year!!\n");
            valid = 0;
        }
    
        return valid;
    }
    
    int isreturntimevalid ( int rentMonth, int rentDay, int rentYear, int returnMonth, int returnDay, int returnYear, int rentHour, int rentMinute, int returnHour, int returnMinute)
    {
        int valid = 1;
    
        if ( (rentYear == returnYear) && (rentMonth == returnMonth) && (rentDay == returnDay ) && (rentHour > returnHour ))
         {
            printf("\nerror with return hour\n");
            valid = 0;
         }
    
        if ( (rentYear == returnYear) && (rentMonth == returnMonth) && (rentDay == returnDay ) && (rentHour == returnHour ) && rentMinute > returnMinute)
        {
            printf("\nerror with return minute\n");
            valid = 0;
        }
    
        if ( (rentDay == returnDay) && ( rentMonth == returnMonth) && ( rentYear == returnYear) ) {
            if ( returnHour < rentHour )
            {
                printf("\nInvalid return Hour!!\n");
                valid = 0;
            }
        }
    
        if ( (rentDay == returnDay) && ( rentMonth == returnMonth) && ( rentYear == returnYear) && ( rentHour == returnHour) ) {
            if ( returnMinute < rentMinute )
            {
                printf("\nInvalid return Minute!!\n");
                valid = 0;
            }
        }
    
        if (((( rentDay == returnDay ) && ( rentMonth == returnMonth) && ( rentYear == returnYear) && ( rentHour == returnHour) && ( rentMinute == returnMinute))))
        {
            printf("\nerror Invalid!!\n");
            valid = 0;
        }
    
        return valid;
    }
    
    int isLeapYear ( int rentYear ) {
    
        int leapYear;
        if ( (rentYear%4 == 0) && (rentYear%100 != 0) )
            leapYear = 1;
        else if ( (rentYear%4 == 0) && (rentYear%100 == 0) && (rentYear%400 == 0) )
            leapYear = 1;
        else if ( (rentYear%4 == 0) && (rentYear%100 == 0) && (rentYear%400 != 0))
            leapYear = 0;
        else
            leapYear = 0;
    
            return leapYear;
    }
    
    int durationhours( int rentHour, int returnHour, int rentMinute, int returnMinute, int rentDay, int returnDay, int currentMonth )
    {
        int rentHourT = 0;
        int rentMinuteT = 0;
        int dayloop = 0;
    
        rentMinuteT = (0-rentMinute)+60+returnMinute;
        if ( rentMinuteT >= 60 ) {
            rentMinuteT = rentMinuteT-60;
            rentHourT = rentHourT+1+((0-rentHour)+returnHour)+23;
        } else if ( rentHourT > 23) {
            int hConvert = rentHourT - 23;
            rentHourT = hConvert - 1;
        } else {
            rentHourT = ((0-rentHour)+returnHour)+23;
        }
    
        if ( rentDay == returnDay )
        {
            if(rentMinute > returnMinute ) {
                if ( returnMinute == 0 ) {
                    rentMinuteT = (rentMinute-60)*-1;
                    rentHourT = (returnHour-rentHour)-1;
                } else if (returnHour - rentHour == 1) {
                    rentHourT = 0;
                    rentMinuteT = (returnMinute-rentMinute)+60;
                } else {
                    rentMinuteT = (60-rentMinute)+returnMinute;
                    rentHourT = (returnHour-rentHour)-1;
                }
            } else if ( rentMinute < returnMinute ) {
                if ( rentMinute == 0 ) {
                    rentMinuteT = rentMinute+returnMinute;
                    rentHourT = returnHour-rentHour;
                } else if ( rentMinuteT >= 60 ) {
                    rentMinuteT = rentMinuteT-60;
                    rentHourT = rentHourT+1+((0-rentHour)+returnHour)+23;
                } else if (rentMinute < returnMinute && rentMinute == 0) {
                    rentMinuteT = (returnMinute-60)*-1;
                } else {
                    rentMinuteT = (rentMinute - returnMinute)*-1;
                    rentHourT = returnHour-rentHour;
                }
            } else {
                rentMinuteT = 0;
                rentHourT = returnHour-rentHour;
            }
    
        } else if ( rentDay > returnDay )
        {
            dayloop = currentMonth-( rentDay-returnDay );
            while( dayloop > 1 ) {
                rentHourT = rentHourT+24;
                dayloop--;
            }
        } else
        {
            dayloop = returnDay-rentDay;
            while( dayloop > 1 ) {
                rentHourT = rentHourT+24;
                dayloop--;
            }
        }
    
        return rentHourT;
    }
    
    int durationminutes( int rentHour, int returnHour, int rentMinute, int returnMinute, int rentDay, int returnDay, int currentMonth )
    {
        int rentHourT = 0;
        int rentMinuteT = 0;
        int dayloop = 0;
    
        rentMinuteT = (0-rentMinute)+60+returnMinute;
        if ( rentMinuteT >= 60 ) {
            rentMinuteT = rentMinuteT-60;
            rentHourT = rentHourT+1+((0-rentHour)+returnHour)+23;
        } else if ( rentHourT > 23) {
            int hConvert = rentHourT - 23;
            rentHourT = hConvert - 1;
        } else {
            rentHourT = ((0-rentHour)+returnHour)+23;
        }
    
        if ( rentDay == returnDay )
        {
            if(rentMinute > returnMinute ) {
                if ( returnMinute == 0 ) {
                    rentMinuteT = (rentMinute-60)*-1;
                    rentHourT = (returnHour-rentHour)-1;
                } else if (returnHour - rentHour == 1) {
                    rentHourT = 0;
                    rentMinuteT = (returnMinute-rentMinute)+60;
                } else {
                    rentMinuteT = (60-rentMinute)+returnMinute;
                    rentHourT = (returnHour-rentHour)-1;
                }
            } else if ( rentMinute < returnMinute ) {
                if ( rentMinute == 0 ) {
                    rentMinuteT = rentMinute+returnMinute;
                    rentHourT = returnHour-rentHour;
                } else if ( rentMinuteT >= 60 ) {
                    rentMinuteT = rentMinuteT-60;
                    rentHourT = rentHourT+1+((0-rentHour)+returnHour)+23;
                } else if (rentMinute < returnMinute && rentMinute == 0) {
                    rentMinuteT = (returnMinute-60)*-1;
                } else {
                    rentMinuteT = (rentMinute - returnMinute)*-1;
                    rentHourT = returnHour-rentHour;
                }
            } else {
                rentMinuteT = 0;
                rentHourT = returnHour-rentHour;
            }
    
        } else if ( rentDay > returnDay )
        {
            dayloop = currentMonth-( rentDay-returnDay );
            while( dayloop > 1 ) {
                rentHourT = rentHourT+24;
                dayloop--;
            }
        } else
        {
            dayloop = returnDay-rentDay;
            while( dayloop > 1 ) {
                rentHourT = rentHourT+24;
                dayloop--;
            }
        }
    
        return rentMinuteT;
    }
    
    void getPrice( int rentHourT, int rentMinuteT, int valid )
    {
        float costOfRent = 0.0;
        if((rentHourT > 0 && rentHourT < 5 ) || (rentHourT == 5 && rentMinuteT == 0)){
            costOfRent = 5;
        } else if ( rentHourT == 5 && rentMinuteT > 0 ) {
            costOfRent = 12;
        } else if ( rentHourT > 5 && rentHourT < 24) {
            costOfRent = 12;
        } else {
            if ( rentMinuteT > 0 )
                rentHourT = rentHourT+1;
            if ( rentHourT == 1 )
                costOfRent = 5;
            else
                costOfRent = 12+((rentHourT-24)*0.5);
        }
        if (valid)
            printf("Cost of Rental: %.2f\n", costOfRent);
        else
            printf("Cost of Rental: ERROR\n");
    }
    
    
    
    
    
    
    
    
    

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

Comments

Twigz has no profile comments yet. Why not say hello?