I'm like a REAL NEWBIE at C++, and I was wondering what is wrong with this code...
Code:#include <iostream.h> #include <stdlib.h> int mult(int x, int y) { return x*y; } int main() { mult(); system("PAUSE"); return 0; }
I'm like a REAL NEWBIE at C++, and I was wondering what is wrong with this code...
Code:#include <iostream.h> #include <stdlib.h> int mult(int x, int y) { return x*y; } int main() { mult(); system("PAUSE"); return 0; }
An Unofficial Cristiano Ronaldo Website : Ronaldo 7
It needs some fixes
Code:#include <iostream> // #include <cstdlib> // standard c++ headers int mult(int, int); //function prototype required before main int main() { int product; int x = 5; // int y = 6; // declare variables x and y and assign values to them product = mult(x, y); // mult() requires two parameters as defined in the prototype // you want to store the value returned by mult() to product system("PAUSE"); return 0; } int mult(int x, int y) //function definition { return x*y; }
I was just reading this: http://www.cprogramming.com/tutorial/lesson13.html , and it says that u dun need to use prototype. Anyways, thx!
An Unofficial Cristiano Ronaldo Website : Ronaldo 7
It's not the function prototyping, it's that in your test you forgot to pass arguments to mult(), and it doesnt have default arguments.
It looks better because people want to see the program as a whole first, which is the main function, and then the detail, which are the definition of functions called inside main()
Also note those tutorials are really out of date, they are pre-C++98 code, so don't pay TOO close attention, especially as they use obsolete headers.Originally posted by Cris987
I was just reading this: http://www.cprogramming.com/tutorial/lesson13.html , and it says that u dun need to use prototype. Anyways, thx!
You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.
thx guys! I just changed my program a bit, but now, nothing happens:
Code:#include <iostream> #include <cstdlib> int add(int x, int y) { return x+y; } int main() { int x = 5; int y = 6; add(x, y); system("PAUSE"); return 0; }
An Unofficial Cristiano Ronaldo Website : Ronaldo 7
you need to add some visual feedback, e.g.
sd::cout << add(x, y) << "\n";
i dun really get the sd:: part. I have seen it before somewhere else, but not in this tutorial. As you guys say it, this tutorial does seem outdated. Are there any good ones out there?
An Unofficial Cristiano Ronaldo Website : Ronaldo 7
first of all laserlight meant to say std:: instead of sd::.Originally posted by Cris987
i dun really get the sd:: part. I have seen it before somewhere else, but not in this tutorial. As you guys say it, this tutorial does seem outdated. Are there any good ones out there?
When you're only starting to learn c++ you could just type this underneath your headers:
this will let you use all the standard calls from the libraries that you included; cout, cin etc etc.Code:using namespace std;
some entropy with that sink? entropysink.com
there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka
icic...I'm still in need of a good , latest tutorial. Isn't there a good site out there? I really dunno where I can find a programming tutorial book..Originally posted by axon
first of all laserlight meant to say std:: instead of sd::.
When you're only starting to learn c++ you could just type this underneath your headers:
this will let you use all the standard calls from the libraries that you included; cout, cin etc etc.Code:using namespace std;
An Unofficial Cristiano Ronaldo Website : Ronaldo 7
Barnes and noble, borders, amazon.com. Look for suggested books on this site.Originally posted by Cris987
icic...I'm still in need of a good , latest tutorial. Isn't there a good site out there? I really dunno where I can find a programming tutorial book..
yeah, I made a typo, sorry about that.
Try your local library.
I think books by SAMS publishing supposedly are pretty good.
ookay~ thx!
An Unofficial Cristiano Ronaldo Website : Ronaldo 7