Page 2 of 5 FirstFirst 1 2 3 4 ... LastLast
Results 21 to 40 of 95

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

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

    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
    Then go ask the prof.

  2. #22
    E. Body
    Join Date
    Jun 2006
    Posts
    2,181
    BG Level
    7
    FFXIV Character
    Bro Teampill
    FFXIV Server
    Gilgamesh
    FFXI Server
    Ifrit

    My guess is he wants you to be able to take command line arguments and convert them from strings to decimals then print out the result. I mean, he's not asking you to do any processing with the values... so who knows. Anyway... this is how that would look:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    struct WEATHER
    {
    	int temp;
    	int humidity;
    };
    
    WEATHER ConvertToWeather(char* szTemp, char* szHumidity)
    {
    	WEATHER weather;
    
    	weather.temp = atoi(szTemp);
    	weather.humidity = atoi(szHumidity);
    
    	return weather;
    }
    int main(int argc, char* argv[])
    {
    	WEATHER weather;
    
    	if(argc != 3)
    	{
    		printf("PWEATHER temperature humidity\r\n\ttemperature\tSpecifies the temperature.\r\n\thumidity\tSpecifies the humidity.\r\n");
    		return 0;
    	}
    
    	weather = ConvertToWeather(argv[1], argv[2]);	
    
    	printf("Temperature: %d degrees. Humidity: %d%%\r\n", weather.temp, weather.humidity);
    
    	return 0;
    }

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

    This is how i wrote it i know i fucked up because i cant compile it

    // homework3.cpp : Defines the entry point for the console application.
    //
    #include "stdafx.h"
    #include <iostream>
    #include <cmath>

    using namespace std;

    int mult (int t, int r)
    {
    return -42.379 + 2.04901523 * t + 10.14333127 * r -0.22475541 * t * r - (6.83783E-3) * pow(t, 2) -(5.48171E-2) * pow(r, 2) + ( 1.22874E-3) * pow(t, 2) * r +(8.5282E-4) * t * r^2 - (1.99E-6) * pow(t, 2) * pow(r, 2);
    }
    int main ()
    {
    int t;
    int x;

    cout << "Please input temperature in Fahrenheit";
    cin >> t;
    cout << "Please input relative humidity";
    cin >> r;
    cout << "The answer is" << mult(int t, int r) << "\n";
    what am i doing wrong D:

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

    you're not reading the compiler error message, that's what you're doing wrong.

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

    Quote Originally Posted by aurik
    you're not reading the compiler error message, that's what you're doing wrong.
    I dont understand it your so negative havent said anything positive yet -_-

  6. #26
    Hydra
    Join Date
    Nov 2006
    Posts
    127
    BG Level
    3

    Quote Originally Posted by LinktheDeme
    Quote Originally Posted by aurik
    you're not reading the compiler error message, that's what you're doing wrong.
    I dont understand it your so negative havent said anything positive yet -_-
    You'll never learn if you don't start analyzing your mistakes with the tools given to you instead of running off to ask other people the moment you have a problem.

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

    my thing looks like the previous one so i don't get why its not working ;/

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

    have you even read what the compiler is saying?

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

    Quote Originally Posted by aurik
    have you even read what the compiler is saying?
    yes and it takes me to some math.h file with some long intense coding and i dont understand that one bit -_-

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

    Well, without seeing the compile error message all I can do is make some educated guesses as to what's going wrong.

    #1: the #include statements might need file extensions, which in this case would probably be <iostream.h> and <cmath.h>.

    #2: that return statement is an awful mess. Clean it the hell up unless you're absolutely sure you know that it's doing the right thing (which you don't). Also, the way it's written, it's being parsed as like 20 different arguments to return. You have to either put parenthesis around it or (better) put the result into another variable and then return that.

    Oh, and that comment at the beginning has nothing to do with what you've written as far as I can tell.

    And on top of all that, there's no } to end the main method (unless you just didn't catch it in the copying.

    edit: if the compiler message takes you to a math.h file, that means you screwed up a function call to something in that file. In this case, it means something went wrong in that return statement, which is no surprise at all.

  11. #31
    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

    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

  12. #32
    Relic Shield
    Join Date
    Oct 2006
    Posts
    1,588
    BG Level
    6

    from the equation i see that, suppose your function should return in term of float or double instead of integer?

    and it is better to define a new variables and just assign the equation to it, and then return the variables.

    and... go read the damn textbook again and again, and learn how to use the index to search for the keywords =.=
    the textbook should have covered everything...

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

    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?

    edit: also i replaced all the r's with x's and it did nothing

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

    Why don't you just ask for someone to do your homework for you?

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

    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

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

    Quote Originally Posted by aurik
    Why don't you just ask for someone to do your homework for you?
    Why do you keep posting if you just wanna bitch -_-

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

    Quote Originally Posted by LinktheDeme
    Quote Originally Posted by aurik
    Why don't you just ask for someone to do your homework for you?
    Why do you keep posting if you just wanna bitch -_-
    Why don't you do your own homework?

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

    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.

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

    Quote Originally Posted by Charla
    Seriously though, there's something wrong
    There is something wrong, the assignment is designed to make him learn how to write functions and he's trying to get other people to do it because he's too incompetent to learn it himself.

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

    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

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