| View previous topic :: View next topic |
| Author |
Message |
paupav Master Cheater
Reputation: 13
Joined: 15 Apr 2011 Posts: 314 Location: P. Sherman 42, Wallaby Way, Sydney
|
|
| Back to top |
|
 |
C-Dizzle Grandmaster Cheater
Reputation: 89
Joined: 16 Mar 2008 Posts: 623
|
Posted: Sat Jan 28, 2012 12:47 pm Post subject: |
|
|
You also need to sort out how your code looks. I'd indent the brackets and cout so it's more indented than the if statement. Same goes with the Pause, make it so it's the same place as return 0;.
Also annotate the fuck out of everything. May sound stupid now but you really need to get practicing with everything you do.
|
|
| Back to top |
|
 |
paupav Master Cheater
Reputation: 13
Joined: 15 Apr 2011 Posts: 314 Location: P. Sherman 42, Wallaby Way, Sydney
|
Posted: Sat Jan 28, 2012 2:41 pm Post subject: |
|
|
| Arktri wrote: | You also need to sort out how your code looks. I'd indent the brackets and cout so it's more indented than the if statement. Same goes with the Pause, make it so it's the same place as return 0;.
Also annotate the fuck out of everything. May sound stupid now but you really need to get practicing with everything you do. |
something like this:
| Code: |
#include <iostream>
#include <string>
using namespace std;
int main()
{
string x;
cout <<"Enter password : \n\n";
cin >> x;
if(x == "blahblahblah")
{
cout <<"12345";
}
system("PAUSE");
return 0;
}
|
|
|
| Back to top |
|
 |
C-Dizzle Grandmaster Cheater
Reputation: 89
Joined: 16 Mar 2008 Posts: 623
|
Posted: Sat Jan 28, 2012 2:52 pm Post subject: |
|
|
| Pretty much but more comments and tab the system and return in once.
|
|
| Back to top |
|
 |
paupav Master Cheater
Reputation: 13
Joined: 15 Apr 2011 Posts: 314 Location: P. Sherman 42, Wallaby Way, Sydney
|
Posted: Sun Jan 29, 2012 4:56 am Post subject: |
|
|
i cant get header files working. can any 1 help me?
add.h
main.cpp
|
|
| Back to top |
|
 |
C-Dizzle Grandmaster Cheater
Reputation: 89
Joined: 16 Mar 2008 Posts: 623
|
Posted: Sun Jan 29, 2012 5:42 am Post subject: |
|
|
| I'm pretty sure you need to add the header to the included directories.
|
|
| Back to top |
|
 |
paupav Master Cheater
Reputation: 13
Joined: 15 Apr 2011 Posts: 314 Location: P. Sherman 42, Wallaby Way, Sydney
|
Posted: Sun Jan 29, 2012 6:10 am Post subject: |
|
|
| Arktri wrote: | | I'm pretty sure you need to add the header to the included directories. |
where is that "included directory"
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Sun Jan 29, 2012 6:01 pm Post subject: |
|
|
You need to give that function a body! All you've done there is give it a signature.
| Code: | int add(int x, int y)
{
return x + y;
} |
Then you can
| Code: | #include <iostream>
#include "add.h"
int main(int argc, const char * argv[])
{
std::cout << add(1, 2) << std::endl;
} |
(You're compiler should make main() return something AUTOMATICALLY)
|
|
| Back to top |
|
 |
C-Dizzle Grandmaster Cheater
Reputation: 89
Joined: 16 Mar 2008 Posts: 623
|
Posted: Sun Jan 29, 2012 6:10 pm Post subject: |
|
|
| Noz3001 wrote: | You need to give that function a body! All you've done there is give it a signature.
| Code: | int add(int x, int y)
{
return x + y;
} |
Then you can
| Code: | #include <iostream>
#include "add.h"
int main(int argc, const char * argv[])
{
std::cout << add(1, 2) << std::endl;
} |
(You're compiler should make main() return something AUTOMATICALLY) |
With the 'std::'. Say I had a cin before cout, would I need to put std:: before them both?
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Sun Jan 29, 2012 6:20 pm Post subject: |
|
|
| Arktri wrote: | | Noz3001 wrote: | You need to give that function a body! All you've done there is give it a signature.
| Code: | int add(int x, int y)
{
return x + y;
} |
Then you can
| Code: | #include <iostream>
#include "add.h"
int main(int argc, const char * argv[])
{
std::cout << add(1, 2) << std::endl;
} |
(You're compiler should make main() return something AUTOMATICALLY) |
With the 'std::'. Say I had a cin before cout, would I need to put std:: before them both? |
Yes, anything in the standard c++ library will need std:: before it in you don't add using namespace std. This is good in big projects, because you can write your own namespace with the same function names and be able to distinguish between them.
std::cout and mynamespace::cout, for example, might do TOTALLY different things
Example for the add function:
| Code: | #include <iostream>
namespace example
{
int add(int x, int y)
{
return x + y;
}
}
int main (int argc, const char * argv[])
{
std::cout << example::add(1, 3) << std::endl;
} |
You should declare namespaces in some header file and give them a counterpart .cpp file though and they can span over various source files. Declaring functions within namespace xxx {} will add them to that namespace no matter what file it is in
|
|
| Back to top |
|
 |
paupav Master Cheater
Reputation: 13
Joined: 15 Apr 2011 Posts: 314 Location: P. Sherman 42, Wallaby Way, Sydney
|
Posted: Mon Jan 30, 2012 7:20 am Post subject: |
|
|
ok... thanks
this gives me error.. why?
|
|
| Back to top |
|
 |
|