Page 1 of 5 1 2 3 ... LastLast
Results 1 to 20 of 95

Thread: C++ question im confused     submit to reddit submit to twitter

  1. #1
    Nidhogg
    Join Date
    Jul 2006
    Posts
    3,999
    BG Level
    7

    C++ question im confused

    Must use a function that accepts the temperature and humidity passed from the main program and returns results for printing in the main program. Programs that do not utilize functions will receive no credit. Remember to attach printout.
    These were the instructions my teacher gave me. . . i know 0 formulas on temp and humidity and i have no idea wtf he is talking about. Also im a bit confused on the concept of a function thats just a name for what i write to make the program work right?

  2. #2
    Chram
    Join Date
    Jun 2006
    Posts
    2,539
    BG Level
    7

    Re: C++ question im confused

    Quote Originally Posted by LinktheDeme
    i know 0 formulas on temp and humidity
    1) Go to google
    2) Enter: temperature humidity formula
    3) Receive bacon

    It is kind of funny how he doesn't say WHAT result he wants.. you could just add them together by that description.

    Quote Originally Posted by LinktheDeme
    Also im a bit confused on the concept of a function thats just a name for what i write to make the program work right?
    Technically OO languages like C++ and Java don't have functions

    I hope this confuses him deeply.

  3. #3
    Relic Horn
    Join Date
    Mar 2006
    Posts
    3,215
    BG Level
    7

    The way I read the problem at first it sounds like the function accepts primitive values or a data structure or something and sticks the two numbers into strings so the main function can call println with them.

    As for the "no functions" thing, I thought C++ compilers also accepted C code most of the time. The way I learned it, function = method.

  4. #4
    Ridill
    Join Date
    May 2005
    Posts
    13,568
    BG Level
    9

    read your god damn textbook

  5. #5
    Nidhogg
    Join Date
    Jul 2006
    Posts
    3,999
    BG Level
    7

    Quote Originally Posted by aurik
    read your god damn textbook
    I did its as vague as my teacher is

    edit: Found a formula for heat index i assume this is what he wats us to use

    Heat Index =
    -42.379 + 2.04901523 * t + 10.14333127 * r

    -0.22475541 * t * r - (6.83783E-3) * t^2

    -(5.48171E-2) * r^2 + ( 1.22874E-3) * t^2 * r

    +(8.5282E-4) * t * r^2 - (1.99E-6) * t^2 * r^2

    "where t is the temperateure in degrees fahrenheit and r is the relative humidity. Write a function to compute thee heat index."


    Is that one big formula? or multiple lines for some other reason because I dont really get this function stuff for C++ :/

    edit #2: Ya its one big formula i just dont get how im supposed to write a function now ;/

  6. #6
    Relic Horn
    Join Date
    Mar 2006
    Posts
    3,215
    BG Level
    7

    The textbook won't tell him if his teacher wants one string, two strings, or two integer values returned. As for what the teacher means by a function, it kinda depends on how he's been using the word so far. He's pretty much got to guess for that part (or ask, but that's just crazy talk).

  7. #7

  8. #8
    Fake Numbers
    Join Date
    Mar 2005
    Posts
    98
    BG Level
    2

    A function is a separate area of code to be referenced.

    You send arguments from your main code to the function, the function ( separate code ) does some shit with those arguments, and then it returns a value.

    The reason you use functions is to reduce redundancy in your program. Say you need to add two values over and over and over and over. Well you can just reference the function you make then, instead of having to type the same code over, and over, and over.

    Get it? If not too bad.

  9. #9
    Nidhogg
    Join Date
    Jul 2006
    Posts
    3,999
    BG Level
    7

    Quote Originally Posted by Tyrn
    A function is a separate area of code to be referenced.

    You send arguments from your main code to the function, the function ( separate code ) does some shit with those arguments, and then it returns a value.

    The reason you use functions is to reduce redundancy in your program. Say you need to add two values over and over and over and over. Well you can just reference the function you make then, instead of having to type the same code over, and over, and over.

    Get it? If not too bad.
    Could you give me a visual example? :/ please

    edit: that website is a little confusing

  10. #10
    Salvage Bans
    Join Date
    Dec 2005
    Posts
    946
    BG Level
    5

    Quote Originally Posted by Charla
    The textbook won't tell him if his teacher wants one string, two strings, or two integer values returned. As for what the teacher means by a function, it kinda depends on how he's been using the word so far. He's pretty much got to guess for that part (or ask, but that's just crazy talk).
    That's part of the learning process. If you don't understand what the teacher/client wants you need to communicate and make sure things are clear.

  11. #11
    Chram
    Join Date
    Jun 2006
    Posts
    2,539
    BG Level
    7

    Quote Originally Posted by Charla
    As for the "no functions" thing, I thought C++ compilers also accepted C code most of the time. The way I learned it, function = method.
    While it is true that C++ compilers usually accept C code.. when you're talking about functions you're talking about a procedural language like C so this isn't really a C++ question

    Function != method

    It seems like just semantics but it really isn't. A function only has the power to access global variables and parameters passed to it. Methods have the power to access all properties of the object they belong to in addition to the parameters passed to it. Functions are isolated and methods are integrated.

    It may not seem like a big difference, but it is actually kind of huge. Lets say I have an array of 10 objects that are actually very different but thanks to polymorphism I can call a print() method on each of them and actually end up calling 10 different pieces of code.

    Print is not some defined stand alone function here, it merely a method I use to interact with these objects and the individual objects are able to run whatever code they want.

    The same logic applies to the difference between a variable and a property. When someone thinks about the variable "a" they imagine one single variable and any change made to "a" is a change made to "a". In OO if I have 10 different apples those apples may each have a different amount of seeds in them. Seeds therefor is just a property each individual apple may have. It just makes more sense.

  12. #12
    Nidhogg
    Join Date
    Jul 2006
    Posts
    3,999
    BG Level
    7

    Quote Originally Posted by Semitry
    Quote Originally Posted by Charla
    The textbook won't tell him if his teacher wants one string, two strings, or two integer values returned. As for what the teacher means by a function, it kinda depends on how he's been using the word so far. He's pretty much got to guess for that part (or ask, but that's just crazy talk).
    That's part of the learning process. If you don't understand what the teacher/client wants you need to communicate and make sure things are clear.
    hes a fob from poland who im surprised knows english

  13. #13
    Salvage Bans
    Join Date
    Dec 2005
    Posts
    946
    BG Level
    5

    Quote Originally Posted by LinktheDeme
    Quote Originally Posted by Semitry
    Quote Originally Posted by Charla
    The textbook won't tell him if his teacher wants one string, two strings, or two integer values returned. As for what the teacher means by a function, it kinda depends on how he's been using the word so far. He's pretty much got to guess for that part (or ask, but that's just crazy talk).
    That's part of the learning process. If you don't understand what the teacher/client wants you need to communicate and make sure things are clear.
    hes a fob from poland who im surprised knows english
    Even better.

  14. #14
    Fake Numbers
    Join Date
    Mar 2005
    Posts
    98
    BG Level
    2

    OK I pulled this sample code from the link above me. This is not my code, I am merely trying to explain what is going on.

    #include <iostream>

    using namespace std;

    int mult ( int x, int y );

    int main()
    {
    int x;
    int y;

    cout<<"Please input two numbers to be multiplied: ";
    cin>> x >> y;
    cin.ignore();
    cout<<"The product of your two numbers is "<< mult ( x, y ) <<"\n";
    cin.get();
    }


    int mult ( int x, int y )
    {
    return x * y;
    }


    Ok you see the statement " mult ( x, y ) " in the main code? That is a function call. That means he is taking two integers >> x, y >> and sending them to the function. In the function, the statement " return x * y " is returning the product of >> x, y >> back to the main code to be printed to the screen.

    GREEN = MAIN CODE RED = FUNCTION

  15. #15
    Ridill
    Join Date
    May 2005
    Posts
    13,568
    BG Level
    9

    Drop the course, you're fucked.

  16. #16
    Chram
    Join Date
    Jun 2006
    Posts
    2,539
    BG Level
    7

    Ya.. computer science is one of those degrees that is pointless to go to school for unless you already knew everything going in to it.

    You need like 10 years at least of training to be any good.

  17. #17
    Nidhogg
    Join Date
    Jul 2006
    Posts
    3,999
    BG Level
    7

    Quote Originally Posted by Devek
    Ya.. computer science is one of those degrees that is pointless to go to school for unless you already knew everything going in to it.

    You need like 10 years at least of training to be any good.
    Im an EE major not computer science. . .

    " int mult ( int x, int y ); " is he multiplying the two variables here? because im confused on how id implement it into that big formula of mine

  18. #18
    Ridill
    Join Date
    May 2005
    Posts
    13,568
    BG Level
    9

    Quote Originally Posted by LinktheDeme
    Quote Originally Posted by Devek
    Ya.. computer science is one of those degrees that is pointless to go to school for unless you already knew everything going in to it.

    You need like 10 years at least of training to be any good.
    Im an EE major not computer science. . .

    " int mult ( int x, int y ); " is he multiplying the two variables here? because im confused on how id implement it into that big formula of mine
    Go ask a TA, they're paid to help you (and you need a LOT of help if you don't even understand what a function is)

  19. #19
    Nidhogg
    Join Date
    Jul 2006
    Posts
    3,999
    BG Level
    7

    Quote Originally Posted by aurik
    Quote Originally Posted by LinktheDeme
    Quote Originally Posted by Devek
    Ya.. computer science is one of those degrees that is pointless to go to school for unless you already knew everything going in to it.

    You need like 10 years at least of training to be any good.
    Im an EE major not computer science. . .

    " int mult ( int x, int y ); " is he multiplying the two variables here? because im confused on how id implement it into that big formula of mine
    Go ask a TA, they're paid to help you (and you need a LOT of help if you don't even understand what a function is)
    dont have any class has only like 14-20 people in it

  20. #20
    Fake Numbers
    Join Date
    Mar 2005
    Posts
    98
    BG Level
    2

    Quote Originally Posted by LinktheDeme
    Quote Originally Posted by Devek
    Ya.. computer science is one of those degrees that is pointless to go to school for unless you already knew everything going in to it.

    You need like 10 years at least of training to be any good.
    Im an EE major not computer science. . .

    " int mult ( int x, int y ); " is he multiplying the two variables here? because im confused on how id implement it into that big formula of mine
    Forget that line, that is a prototype for the function, because this dumbass decided to write the function below the main code. Just put the function definition before your main code, and you'll be fine.

    The place you need to do all your math for your problem is in the function. That red area I marked off before.

    And seriously........ smoke em if you got em, you're fucked.

Page 1 of 5 1 2 3 ... LastLast

Similar Threads

  1. a tech question because im a noob
    By Medivac in forum General Discussion
    Replies: 11
    Last Post: 2006-09-21, 23:57
  2. Just got a question for you guys
    By Blackwar in forum General Discussion
    Replies: 3
    Last Post: 2004-08-06, 20:14
  3. psst.. im at work...
    By Judah in forum General Discussion
    Replies: 6
    Last Post: 2004-07-19, 14:47