Then go ask the prof.Originally Posted by LinktheDeme
Then go ask the prof.Originally Posted by LinktheDeme
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; }
This is how i wrote it i know i fucked up because i cant compile it
what am i doing wrong D:// 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";
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 -_-Originally Posted by aurik
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.Originally Posted by LinktheDeme
my thing looks like the previous one so i don't get why its not working ;/
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 -_-Originally Posted by aurik
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.
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
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...
how did you clean it up?Originally Posted by Eanae
edit: also i replaced all the r's with x's and it did nothing
Why don't you just ask for someone to do your homework for you?
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 lolOriginally Posted by LinktheDeme
Why do you keep posting if you just wanna bitch -_-Originally Posted by aurik
Why don't you do your own homework?Originally Posted by LinktheDeme
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.Originally Posted by LinktheDeme
Seriously though, there's something wrong if you think "return x + y * z + pow(n, 2)" is a good idea.
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.Originally Posted by Charla
Could you give me an example of an assignment please?Originally Posted by Charla
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