Gamma Ray's Profile User Rating: -----

Reputation: 12 Tradesman
Group:
Active Members
Active Posts:
144 (0.1 per day)
Joined:
24-September 10
Profile Views:
3,045
Last Active:
User is offline Sep 29 2014 09:37 PM
Currently:
Offline

Previous Fields

Country:
NO
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
Intel
Favorite Gaming Platform:
Nintendo
Your Car:
Who Cares
Dream Kudos:
0

Latest Visitors

Icon   Gamma Ray , Gamma Ray, Gamma, Gamma, Gamma Ray

Posts I've Made

  1. In Topic: A little help with my assignment

    Posted 29 Sep 2014

    Uhm, I'm not sure if you fully understood what I was saying.
    int isRentTimeValid ( int rentHour, int rentMinute ) {
    
        int invalid;
        if ( rentHour >= 0 && rentHour <= 23) {
            invalid = 0;
        } else {
            printf("\nInvalid rent Hour!!\n");
            invalid = 1;
        }
        if ( rentMinute >= 0 && rentMinute  <= 59) {
            invalid = 0;
        } else {
            printf("\nInvalid rent Minute!!\n");
            invalid = 1;
        }
        return invalid;
    }
    
    int isReturnTimeValid ( int returnHour, int returnMinute ) {
    
        int invalid;
        if (returnHour >= 0 && returnHour <= 23) {
            invalid = 0;
        } else {
            printf("\nInvalid return Hour!!\n");
            invalid = 1;
        }
        if (returnMinute >= 0 && returnMinute <= 59) {
            invalid = 0;
        } else {
            printf("\nInvalid return Minute!!\n");
            invalid = 1;
        }
        return invalid;
    }
    
    


    These two functions do the exact same thing.
    Which is why you should just have ONE function.
  2. In Topic: not really a "bad code"

    Posted 29 Sep 2014

    Quote

    if(!isset($caffeine) && !isset($keyboard) && !isset($monitor) && !isset($music))
    {
      $this->watchPorn($url);
    }
    


    You watch porn without a monitor?
    You can't even say you listen to the audio, because you have no $music either.
  3. In Topic: A little help with my assignment

    Posted 28 Sep 2014

    Nope. Now you are checking two at once. You are checking both rent and return date and times.

    It should be more like this:

    bool validRentDate = false;
    bool validReturnDate = false;
    
    if (dateIsValid(rentYear, rentDay, rentMonth)) {
        validRentDate = true;
    }
    if (dateIsValid(returnYear, returnDay, returnMonth)) {
        validReturnDate = true;
    }
    


    Edit:
    Maybe I should explain more 'why'.

    You want to create your code as re-usable as possible.
    For example, if you need another date-check down the road, you can't use your "dateIsValid(rentYear, rentDay, rentMonth, returnYear, returnDay, returnMonth)" because maybe you don't need to check two dates at once.

    Therefore it's better to check one, because then you can just simply use that one all the time instead of creating a new function to do that.

    Then, if you were to check 100s of dates. You could simply do:

    for (int i = 0; i < 1000; i++) {
        if (!dateIsValid(year[i], day[i], month[i])) { // the ! means " == false" basically.
            printf("Invalid date");
        }
    }
    


    I assume you know what an array is? You should be able to get the above example either way I hope.
  4. In Topic: A little help with my assignment

    Posted 28 Sep 2014

    Great. But maybe you should check only one date and one time at once.
  5. In Topic: A little help with my assignment

    Posted 27 Sep 2014

    View PostTwigz, on 27 September 2014 - 05:52 PM, said:

    Ahh lol, any suggestions on how to start? i mean like how i can split it?

    You can start with the "bool date_is_valid(int rentMonth int rentDay, int rentYear,....................)" function.
    Then use that instead of that huge if-nest.

My Information

Member Title:
D.I.C Head
Age:
19 years old
Birthday:
August 5, 1995
Gender:
Location:
Norway
Interests:
Programming? :D
Full Name:
Sebastian
Years Programming:
4
Programming Languages:
C++, PHP, JavaScript, C, x86 Assembly (NASM)

Contact Information

E-mail:
Click here to e-mail me

Friends

Comments

Page 1 of 1
  1. Photo

    Gamma Ray Icon

    14 Oct 2011 - 08:08
    Lol, I didn't mean to be rude or anything. Just felt you deserved that one :)
  2. Photo

    smohd Icon

    14 Oct 2011 - 07:21
    Thanks budy, but that is how it works, cant do that in W7 or at least my Ultimate version
  3. Photo

    Gamma Ray Icon

    20 Jul 2011 - 07:15
    ^_^
  4. Photo

    assert(C) Icon

    20 Jul 2011 - 07:14
    Hey dude any help is great thanks for the reply
Page 1 of 1