How much do courses at the University of BlueGartr cost?
How much do courses at the University of BlueGartr cost?
I've barely ever programmed in my life and I know you're fucked.
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.
The problem is, you don't even seem to know the basic grammar of the language.Originally Posted by LinktheDeme
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.
master course does not has any TA lolOriginally Posted by MisterBob
[quote=Osede]master course does not has any TA lol[/quote:e3628]Originally Posted by MisterBob
This is most definitely not a Masters Course.
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.
No. Functions are part of the C++ Standard.Originally Posted by Devek
you can clearly see Java doesn't really have a function. It's a more pure-OO programming languageOriginally Posted by Taj
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 MethodsOriginally Posted by VZX
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.Originally Posted by Devek
Okay before i try to do that monster equation im trying a smaller grade of the equation it follows ;
There is two errors with it the t, and x are not declared(at the cin).// 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);
}
i thought that i declared them above at the top os there wouldnt be a problem. Unless i'm writing it wrong?
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"?Originally Posted by LinktheDeme
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.
ScopeOriginally Posted by LinktheDeme
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.
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)Originally Posted by divisortheory
What's the name of your textbook?Originally Posted by LinktheDeme
"C++ An introduction to Computing" Third editionOriginally Posted by divisortheory
by Joel adams and Larry nyhoff
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.Originally Posted by Zhais
you can't declare global variables then try to declare them againOriginally Posted by LinktheDeme
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.