Page 3 of 5 FirstFirst 1 2 3 4 5 LastLast
Results 41 to 60 of 95

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

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

    How much do courses at the University of BlueGartr cost?

  2. #42
    A Magic Ham Sandwich
    Join Date
    Nov 2005
    Posts
    5,386
    BG Level
    8

    I've barely ever programmed in my life and I know you're fucked.

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

    Sorry, I meant a declaration. Those silly programming terms.

    Assignment examples:
    a = 5;
    n = x + y;
    temp = x*y + 3;

    Declaration examples:
    int a;
    char temp;
    long x;
    unsigned long int stuff;

    And here's a declaration that's also an assignment:
    int at = 0;

    Stuff not to do:
    pow(int x, 1);
    mult(int a, int b);
    int x + int y;
    return x + y;

    Stuff to never ever do:
    return (int x + int y);

    Stuff nobody should even think about doing:
    goto malloc(0);

    Sorry, I got a little carried away... And remember, I don't even know C++, this is all based on C. They're pretty similar for this simple stuff at least.

  4. #44
    netz
    Guest

    Quote Originally Posted by LinktheDeme
    Quote Originally Posted by Eanae
    cout << "The answer is" << mult(t, x) << "\n";

    not

    cout << "The answer is" << mult(int t, int x) << "\n";


    You're not declaring variables twice here... also, in my opinion endl is alot neater then "\n" is to declare a new line. Clean up the interface a bit and it's finished really...


    also, charge your r's in main() to x or change int x; to int r;. Your entire program looks like one big mess.

    ps: if you clean it up, your program works fine:

    http://i3.photobucket.com/albums/y95.../worksfine.jpg

    edit: I didn't check the math because it isn't my project and I don't care if it's right or not lol
    how did you clean it up?
    The problem is, you don't even seem to know the basic grammar of the language.

    Basic function prototype:
    <return type> <function name>(<parameters>)
    {
    code here;
    }

    Complete lines of code are terminated with a semicolon. Whitespace is largely irrelevant; a line of code that looks like this:
    fd = fopen("filename.txt",
    "w");
    is perfectly acceptable to the compiler. To span strings across lines, you can use \ and it'll keep on reading to the next line without adding any whitespace to the string, like:
    static char whatever[] = "This is a multi line" \
    " String example that I'm using for the sake" \
    " of demonstration";

    The final line still needs to be correctly terminated. Other languages can use + for a similar result, but in C++ for that to work, you'd have to overload the + operator to work as strcat or a similar function.

    When passing arguments to a function, the type doesn't need to be specified, unless you're specifically trying to invoke a typecast. Typecasts are used in situations where you presumably know what you're doing, and wish to have the function accept an object of a different type from what it typically accepts, or returning a result from a function of a different type than the variable to which it will be assigned.

    In your example:
    cout << "The answer is" << mult(int t, int x) << "\n";

    Eanae already told you what to write correctly, but just to illustrate a typecast:
    cout << "The answer is" << mult((int)t, (int)x) << "\n";

    In this example, you'd be instructing the compiler to accept t and x as ints, despite the fact that they may not necessarily be that datatypes. If they are already ints, then you're not really going to accomplish much by adding that to your statement. If you declared them as float, and passed them to mult simply as mult(t, x) you'd run into an error. Keep in mind that if you use a type cast to force the function to accept those values, you should be aware that you'd potentially be losing data -- the fractional amounts would be thrown away.

    When compiling a program, you're really going to have to learn how to read the errors generated, since they make most problems look plain as fucking day until you make the mistake of using the standard template library (and then you'd need to be on acid to read the verbage spewed forth from an incorrect usage). It's going to tell you at the earliest opportunity where you missed a semicolon or a bracket; it's your job to hunt backwards and make sure everything is paired correctly. Source highlighting editors like vim and Visual Studio can make this easier, since you'll see the wrong colors for things on the wrong lines.

    Like many others suggested, you're going to have to consult the front of your book and really figure out how to understand the syntax. If your book lacks such a thing, it's your job to find another book that will explain it to you, or go searching on Google for a basic explanation.

  5. #45
    Relic Shield
    Join Date
    Oct 2006
    Posts
    1,588
    BG Level
    6

    Quote Originally Posted by MisterBob
    Quote Originally Posted by LinktheDeme
    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
    What craphole do you go to that has no TA in a class with 14-20? I wouldn't be paying to go there, that's for sure lol
    master course does not has any TA lol

  6. #46
    Nidhogg
    Join Date
    Oct 2005
    Posts
    3,612
    BG Level
    7
    FFXIV Character
    Glick Wick
    FFXIV Server
    Ultros
    FFXI Server
    Bahamut

    [quote=Osede]
    Quote Originally Posted by MisterBob
    Quote Originally Posted by LinktheDeme
    Quote Originally Posted by aurik
    Quote Originally Posted by LinktheDeme
    Quote Originally Posted by "Devek":e3628
    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
    What craphole do you go to that has no TA in a class with 14-20? I wouldn't be paying to go there, that's for sure lol
    master course does not has any TA lol[/quote:e3628]

    This is most definitely not a Masters Course.

  7. #47
    Relic Shield
    Join Date
    Oct 2006
    Posts
    1,588
    BG Level
    6

    I did have a course that does not has any TA before during my undergrad. But it due to the professor only teach a course in a semester and u can found him in his office 80% of anytimes you want to pay a visit to him.

  8. #48
    Taj
    Taj is offline
    Old Merits
    Join Date
    Mar 2006
    Posts
    1,170
    BG Level
    6

    Re: C++ question im confused

    Quote Originally Posted by Devek
    Technically OO languages like C++ and Java don't have functions
    No. Functions are part of the C++ Standard.

  9. #49
    VZX
    VZX is offline
    Relic Shield
    Join Date
    Dec 2006
    Posts
    1,700
    BG Level
    6
    FFXI Server
    Asura

    Re: C++ question im confused

    Quote Originally Posted by Taj
    Quote Originally Posted by Devek
    Technically OO languages like C++ and Java don't have functions
    No. Functions are part of the C++ Standard.
    you can clearly see Java doesn't really have a function. It's a more pure-OO programming language

    you still can see some functions in C++ because they are extended OO version of C. At least that's what I learned from using C++ for 5/6 semesters

  10. #50
    Nidhogg
    Join Date
    Oct 2005
    Posts
    3,612
    BG Level
    7
    FFXIV Character
    Glick Wick
    FFXIV Server
    Ultros
    FFXI Server
    Bahamut

    Re: C++ question im confused

    Quote Originally Posted by VZX
    Quote Originally Posted by Taj
    Quote Originally Posted by Devek
    Technically OO languages like C++ and Java don't have functions
    No. Functions are part of the C++ Standard.
    you can clearly see Java doesn't really have a function. It's a more pure-OO programming language

    you still can see some functions in C++ because they are extended OO version of C. At least that's what I learned from using C++ for 5/6 semesters
    Correct. Only functions within classes in C++ are referred to as Methods

  11. #51
    Yoshi P
    Join Date
    Jul 2005
    Posts
    5,016
    BG Level
    8

    Quote Originally Posted by Devek
    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.
    Unfortunately, your argument fails because C++ is not (and was never intended to be) a purely object oriented language like, for example, Smalltalk. Therefore it's perfectly acceptable to speak of C++ "functions" that access global variables. it's not the C++ compiler compiling C code, it's the C++ compiler compiling C++ code.

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

    Okay before i try to do that monster equation im trying a smaller grade of the equation it follows ;

    // homewoxk3.cpp : Defines the entxy point fox the console application.
    //
    #include "stdafx.h"
    #include <iostream>
    #include <cmath>

    using namespace std;

    double Temp (int t, int x);


    int main ()
    {
    cout << "Please input temperature in Fahrenheit ";
    cin >> t;
    cout << "Please input relative humidity ";
    cin >> x;
    cout << "The answer is " << Temp << "\n";
    }

    double Temp (double t, double x)
    {
    return (t - x);
    }
    There is two errors with it the t, and x are not declared(at the cin).

    i thought that i declared them above at the top os there wouldnt be a problem. Unless i'm writing it wrong?

  13. #53
    Yoshi P
    Join Date
    Jul 2005
    Posts
    5,016
    BG Level
    8

    Quote Originally Posted by LinktheDeme
    Quote Originally Posted by Charla
    Quote Originally Posted by LinktheDeme

    how did you clean it up?
    Well, he fixed your function call with assignments in it, then he probably made another variable to stick the final result in before returning it, kinda like we've all been saying to do.

    Seriously though, there's something wrong if you think "return x + y * z + pow(n, 2)" is a good idea.
    Could you give me an example of an assignment please?

    edit: @ aurik how the fuck am i supposed to learn how to do that complicated shit with no knowledge base on functions in my 3rd class
    While I won't take quite as abrupt of a stance as aurik, I do agree with him. How can you honestly ask for an example of an assignment and not expect people to be like "wtf"?

    The reason he's bashing you is because you are making no effort on your own to actually learn this material. You're taking the standard cop out approach of "holy shit it's complicated wtf is going on lemme ask someone else" without making a serious and dedicated effort to figure it out. Not knowing what an "assignment" is means you probably need to drop the class. It's more or less the same as signing up for College Algebra and then asking someone to explain what addition is. it's probably explained on page 1 or 2 of your book. If you even know what the word "assignment" means in the English language, and you've actually made a serious effort to look at your book for more than 5 minutes, you would have seen a glaring example of something and said "holy shit, I bet that's an assignment."

    The problme is you're throwing your hands up in the air at the slightest hint of adversity, when quite frankly even the lowest of the lowest common denominator could figure it out with a little effort.

  14. #54
    Yoshi P
    Join Date
    Jul 2005
    Posts
    5,016
    BG Level
    8

    Quote Originally Posted by LinktheDeme
    There is two errors with it the t, and x are not declared(at the cin).

    i thought that i declared them above at the top os there wouldnt be a problem. Unless i'm writing it wrong?
    Scope

    And yes, I'm intentionally making you work for the answer. Your book definitely explains rules regarding where you have to "declare" variables in order to be able to access them.

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

    Quote Originally Posted by divisortheory
    Quote Originally Posted by LinktheDeme
    Quote Originally Posted by Charla
    Quote Originally Posted by LinktheDeme

    how did you clean it up?
    Well, he fixed your function call with assignments in it, then he probably made another variable to stick the final result in before returning it, kinda like we've all been saying to do.

    Seriously though, there's something wrong if you think "return x + y * z + pow(n, 2)" is a good idea.
    Could you give me an example of an assignment please?

    edit: @ aurik how the fuck am i supposed to learn how to do that complicated shit with no knowledge base on functions in my 3rd class
    While I won't take quite as abrupt of a stance as aurik, I do agree with him. How can you honestly ask for an example of an assignment and not expect people to be like "wtf"?

    The reason he's bashing you is because you are making no effort on your own to actually learn this material. You're taking the standard cop out approach of "holy shit it's complicated wtf is going on lemme ask someone else" without making a serious and dedicated effort to figure it out. Not knowing what an "assignment" is means you probably need to drop the class. It's more or less the same as signing up for College Algebra and then asking someone to explain what addition is. it's probably explained on page 1 or 2 of your book. If you even know what the word "assignment" means in the English language, and you've actually made a serious effort to look at your book for more than 5 minutes, you would have seen a glaring example of something and said "holy shit, I bet that's an assignment."

    The problme is you're throwing your hands up in the air at the slightest hint of adversity, when quite frankly even the lowest of the lowest common denominator could figure it out with a little effort.
    I've been trying to figure this shit out since 12:00 PM CST and its now 10:00 PM CST. i know very little of programming and have looked at every page about 10 times. There has only been 3 classes (50 minute classes)

  16. #56
    Yoshi P
    Join Date
    Jul 2005
    Posts
    5,016
    BG Level
    8

    Quote Originally Posted by LinktheDeme
    I've been trying to figure this shit out since 12:00 PM CST and its now 10:00 PM CST. i know very little of programming and have looked at every page about 10 times. There has only been 3 classes (50 minute classes)
    What's the name of your textbook?

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

    Quote Originally Posted by divisortheory
    Quote Originally Posted by LinktheDeme
    I've been trying to figure this shit out since 12:00 PM CST and its now 10:00 PM CST. i know very little of programming and have looked at every page about 10 times. There has only been 3 classes (50 minute classes)
    What's the name of your textbook?
    "C++ An introduction to Computing" Third edition

    by Joel adams and Larry nyhoff

  18. #58
    Bagel
    Join Date
    Jan 2006
    Posts
    1,428
    BG Level
    6

    if this is the starter programming course... either your teacher must suck, your book sucks, a combination of the two, or you're sleeping through class and didn't buy the book.

    Books usually have tons of examples in them. Look at a few, look at the structure. Replace var names, replace the functionality of the functions or methods or whatever you want to call them, and you have yourself a good deal.

    That and google can help. Wikipedia. Etc.

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

    Quote Originally Posted by Zhais
    if this is the starter programming course... either your teacher must suck, your book sucks, a combination of the two, or you're sleeping through class and didn't buy the book.

    Books usually have tons of examples in them. Look at a few, look at the structure. Replace var names, replace the functionality of the functions or methods or whatever you want to call them, and you have yourself a good deal.

    That and google can help. Wikipedia. Etc.
    I dont sleep through class teacher sucks book is mediocre. I'm actually sitting in front swamping him with questions most of times. What he teaches isnt normally relevant to hw either.

  20. #60
    Nikkei's Hoe
    Worse than her at uno

    Join Date
    Dec 2006
    Posts
    6,236
    BG Level
    8
    FFXIV Character
    Eanae Hikari
    FFXIV Server
    Gilgamesh
    FFXI Server
    Cerberus
    WoW Realm
    Hyjal

    Quote Originally Posted by LinktheDeme
    Okay before i try to do that monster equation im trying a smaller grade of the equation it follows ;

    // homewoxk3.cpp : Defines the entxy point fox the console application.
    //
    #include "stdafx.h"
    #include <iostream>
    #include <cmath>

    using namespace std;


    double Temp (int t, int x);

    int main ()
    {
    cout << "Please input temperature in Fahrenheit ";
    cin >> t;
    cout << "Please input relative humidity ";
    cin >> x;
    cout << "The answer is " << Temp << "\n";
    }

    double Temp (double t, double x)
    {
    return (t - x);
    }
    There is two errors with it the t, and x are not declared(at the cin).

    i thought that i declared them above at the top os there wouldnt be a problem. Unless i'm writing it wrong?
    you can't declare global variables then try to declare them again

    edit: you still haven't learned the concept of a header file either

    also your double Temp (int t, int x); at the top is completely wrong. The whole point of a function is to use localized variables.

Page 3 of 5 FirstFirst 1 2 3 4 5 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