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;
}
Printable View
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;
}
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!:D
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.Quote:
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!:D
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;
}
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? :rolleyes:
For a good tutorial get one good book.
first of all laserlight meant to say std:: instead of sd::.Quote:
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? :rolleyes:
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;
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..:(Quote:
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;
Barnes and noble, borders, amazon.com. Look for suggested books on this site.Quote:
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! :D
libraries usually have pretty outdated programming books...at least around me that is. Try google my friend...or different university websites cs departments; there is a lot of good stuff c++ wise out there.Quote:
Originally posted by laserlight
yeah, I made a typo, sorry about that.
Try your local library.
I think books by SAMS publishing supposedly are pretty good.
try a university that teaches C++ programming courses... sometimes a copy of their old textbook goes in their library...