1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C++ HELP!!!!! CodeLab

Discussion in 'BlackHat Lounge' started by Designerdude13, Sep 26, 2012.

  1. Designerdude13

    Designerdude13 Power Member

    Joined:
    Nov 22, 2010
    Messages:
    645
    Likes Received:
    188
    Gender:
    Male
    Can someone help me please with is problem
    C++

    Code:
     Write the definition of a function  signOf , that receives an integer parameter and returns a -1 if the parameter is negative, returns 0 if the parameter is 0 and returns 1 if the parameter is positive. 
    
     So, if the parameter's value is 7 or 803 or 141 the function returns 1. But if the parameter's value is -22 or -57, the function returns -1. And if the parameter's value is 0, the function returns 0.
     
  2. qrazy

    qrazy Senior Member

    Joined:
    Mar 19, 2012
    Messages:
    1,111
    Likes Received:
    1,712
    Location:
    Banana Republic
    This looks very very basic and what's the problem you find in solving it? You need to have a 'switch case' or multiple 'if' conditions to solve it.
     
  3. Designerdude13

    Designerdude13 Power Member

    Joined:
    Nov 22, 2010
    Messages:
    645
    Likes Received:
    188
    Gender:
    Male
    Yea but I don't know how to do that

    I also don't know which integer parameter to use
     
  4. qrazy

    qrazy Senior Member

    Joined:
    Mar 19, 2012
    Messages:
    1,111
    Likes Received:
    1,712
    Location:
    Banana Republic
    Try this.. hope you know how to call a function & compile it.
    PHP:
    int signOf(int input)
    {
        if(
    input 0)
             return -
    1;
        else if(
    input == 0)
        return 
    0;
        else
        return 
    1;

    }
     
    • Thanks Thanks x 1
  5. Designerdude13

    Designerdude13 Power Member

    Joined:
    Nov 22, 2010
    Messages:
    645
    Likes Received:
    188
    Gender:
    Male

    THANK YOU!!!! YOU'RE A GENIUS!!! How come you had to use "else"?
     
  6. qrazy

    qrazy Senior Member

    Joined:
    Mar 19, 2012
    Messages:
    1,111
    Likes Received:
    1,712
    Location:
    Banana Republic
    'else' is for every other number which is not negative or equals zero, so for any positive number the code inside else be executed.
     
  7. Ruger

    Ruger BANNED BANNED

    Joined:
    Sep 14, 2010
    Messages:
    179
    Likes Received:
    28
    It's Ballerina Time!!
     
  8. Designerdude13

    Designerdude13 Power Member

    Joined:
    Nov 22, 2010
    Messages:
    645
    Likes Received:
    188
    Gender:
    Male
    Write the definition of a function named quadratic that receives three double parameters a , b , c . If the value of a is 0 then the function prints the message "no solution for a=0" and returns. If the value of "b squared" - 4ac is negative, then the code prints out the message "no real solutions" and returns. Otherwise the function prints out the largest solution to the quadratic equation. The formula for the solutions to this equation can be found here: Quadratic Equation on Wikipedia.
     
  9. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,148
    So, someone was kind enough to do your homework and your first though was "sweet, let's post some more"?

    Is this how you deal with IM as well? Unless you give the effort and dedication to increase your knowledge, your business future will be the same as your programing skills - pathetic. Stop partying and shit - get to work.
     
  10. Designerdude13

    Designerdude13 Power Member

    Joined:
    Nov 22, 2010
    Messages:
    645
    Likes Received:
    188
    Gender:
    Male
    First avowal as a moderator it would be nice if you could show some respect. I wasn't partying and I only had 1 more question. If I was partying, I wouldn't be on this forum using my resources to get help.
     
  11. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,148
    Seems like the partying line hit a nerve there. Oh - and you need to check your auto-speller - it changed a misspelled "of all" to "avowal".

    Moderation status has nothing to do with this. I neither locked the thread nor deleted your post or anything else.

    I am still entitled to my opinion and my opinion (in case it 's not clear yet) is that begging for homework solutions instead of taking the chance to actually increase your skill set is pathetic.

    Edit: You can keep minus repping me whenever you can. It will not make you a programmer but if it makes you sleep better, it 's fine by me :)
     
    Last edited: Sep 26, 2012
  12. Designerdude13

    Designerdude13 Power Member

    Joined:
    Nov 22, 2010
    Messages:
    645
    Likes Received:
    188
    Gender:
    Male
    Check the dictionary. Avowal is definitely a word and I used it in its right context. And I'm not BEGGING for my homework solutions. I've actually attempted the problem, but I'm trying to see where I went wrong. If I was begging, I would've posted all of the questions and simply said help me do these. And no, the partying line didn't hit a nerve there...it was actually the cursing. Chill on me
     
  13. hatemachine

    hatemachine Regular Member

    Joined:
    Jan 14, 2011
    Messages:
    271
    Likes Received:
    1,138
    Why didn't you post your attempt then? :) Anyways. Since you're not interested into programming but have the course for some weird reason, just pay someone on fiverr to do it.
     
  14. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,148
    Indeed you are correct, I erred about its syntactical use. I apologize for that, I should have checked.

    Had you post your non-working code and asked what 's wrong with that would make it believable.
     
  15. Designerdude13

    Designerdude13 Power Member

    Joined:
    Nov 22, 2010
    Messages:
    645
    Likes Received:
    188
    Gender:
    Male
    Assume that two int constants, FIRST_YEAR and LAST_YEAR have already been declared and initialized with year values (like 2009, 2014), along with a double variable oil that has been initialized with the number of barrels of oil consumed in Canada in the year given by FIRST_YEAR . Write some code that uses a while statement to print on a line by itself, each of the years from FIRST_YEAR to LAST_YEAR inclusive. On each line, after the year, separated by a colon and a space, print the new value amount of oil , taking into account that each year the oil consumed increases by 20%.

    This is what I have and it's wrong :(

    Code:
    while ((FIRST_YEAR <= LAST_YEAR)) {
    
    cout << FIRST_YEAR << ":" <<" "<< oil endl;
    oil=((oil*20) / 100 );
    
    
    FIRST_YEAR++;
    
    
    }

    Help please!
     
  16. Designerdude13

    Designerdude13 Power Member

    Joined:
    Nov 22, 2010
    Messages:
    645
    Likes Received:
    188
    Gender:
    Male
    I figured it out. You can't modify constants.... -_-