1337codez™
Would you like to react to this message? Create an account in a few clicks or log in to continue.



 
HomeHome  PortalPortal  Latest imagesLatest images  RegisterRegister  Log inLog in  

 

 Random Tip #2 - Utilizing Whitespace

Go down 
2 posters
AuthorMessage
Wander
C++ Expert
Wander


Posts : 72
Join date : 2010-08-10
Location : Florida

Random Tip #2 - Utilizing Whitespace Empty
PostSubject: Random Tip #2 - Utilizing Whitespace   Random Tip #2 - Utilizing Whitespace EmptyWed Aug 11, 2010 3:15 pm

In my personal experience, I have noticed that the code must stay organized throughout the process of coding it. As your code gets bigger, it becomes imperative to keep it as neat as possible. One of the ways that I keep my code organized is I use the whitespace that C++ gives to me. Spread your code out. Don't spread it out too much though. The reason C++ allows you to use whitespace (empty lines and spots where code isn't present) is so you CAN keep your code organized and you can read it.

Code:
#include <iostream>

using namespace std;

int add(int,int);

int add(int a, int b)
{
  return a+b;
}

int main()
{
  int a, b, c;
  cout << "Please enter a number: " << endl;
  cin >> a;

  cout << "Please enter another number: " << endl;
  cin >> b;

  c = add(a,b);

  cout << c << endl;

  system("PAUSE");
  return 0;
}

Notice how I separated the sections where different things are going on. Spacing everything out like this allows you to better read the code. I also spaced the operators one space away from the actual variables.

Think about it this way. If you do this then your code takes up more lines and you can brag about how large your code is. Very Happy


-Wander

I'll be posting more about C++ here on this forum.
For my in-progress line of tutorials, visit my website: http://letslearncpp.forumstech.com/
For the corresponding video tutorial line; my YouTube channel is: LetsLearnCPP
Back to top Go down
http://letslearncpp.forumstech.com/
DarK_DemoN
»[\...VIP.../]«™ AdminiStratoR
DarK_DemoN


Posts : 584
Join date : 2010-07-20
Age : 31
Location : Hacking Kingdom, USA

Random Tip #2 - Utilizing Whitespace Empty
PostSubject: Re: Random Tip #2 - Utilizing Whitespace   Random Tip #2 - Utilizing Whitespace EmptyWed Aug 11, 2010 4:44 pm

lol, good point, larger=brag rights. lol
Back to top Go down
http://odstofficalsite.webs.com
Wander
C++ Expert
Wander


Posts : 72
Join date : 2010-08-10
Location : Florida

Random Tip #2 - Utilizing Whitespace Empty
PostSubject: Re: Random Tip #2 - Utilizing Whitespace   Random Tip #2 - Utilizing Whitespace EmptyWed Aug 11, 2010 4:46 pm

heck yeah! XD I once wrote a program that was over 3000 lines of code hahahaha
Back to top Go down
http://letslearncpp.forumstech.com/
DarK_DemoN
»[\...VIP.../]«™ AdminiStratoR
DarK_DemoN


Posts : 584
Join date : 2010-07-20
Age : 31
Location : Hacking Kingdom, USA

Random Tip #2 - Utilizing Whitespace Empty
PostSubject: Re: Random Tip #2 - Utilizing Whitespace   Random Tip #2 - Utilizing Whitespace EmptyWed Aug 11, 2010 4:56 pm

holy crap! lol. seriously spaced out im guessing
Back to top Go down
http://odstofficalsite.webs.com
Wander
C++ Expert
Wander


Posts : 72
Join date : 2010-08-10
Location : Florida

Random Tip #2 - Utilizing Whitespace Empty
PostSubject: Re: Random Tip #2 - Utilizing Whitespace   Random Tip #2 - Utilizing Whitespace EmptyWed Aug 11, 2010 4:57 pm

Nope. It was actually before I even thought about organizing my code. I was a jumbled mess. Lol
Back to top Go down
http://letslearncpp.forumstech.com/
DarK_DemoN
»[\...VIP.../]«™ AdminiStratoR
DarK_DemoN


Posts : 584
Join date : 2010-07-20
Age : 31
Location : Hacking Kingdom, USA

Random Tip #2 - Utilizing Whitespace Empty
PostSubject: Re: Random Tip #2 - Utilizing Whitespace   Random Tip #2 - Utilizing Whitespace EmptyWed Aug 11, 2010 8:06 pm

lol wow then thats a huge program. whats it do?
Back to top Go down
http://odstofficalsite.webs.com
Wander
C++ Expert
Wander


Posts : 72
Join date : 2010-08-10
Location : Florida

Random Tip #2 - Utilizing Whitespace Empty
PostSubject: Re: Random Tip #2 - Utilizing Whitespace   Random Tip #2 - Utilizing Whitespace EmptyWed Aug 11, 2010 8:10 pm

It was a game. Lol! Me and a friend were working on it together. I had the idea to make it and I started making it. Got to about 1000 lines and then showed him the code and we teamed up. We added a GUI, keyboard controls, cheats, AI, and color schemes haha.
Back to top Go down
http://letslearncpp.forumstech.com/
DarK_DemoN
»[\...VIP.../]«™ AdminiStratoR
DarK_DemoN


Posts : 584
Join date : 2010-07-20
Age : 31
Location : Hacking Kingdom, USA

Random Tip #2 - Utilizing Whitespace Empty
PostSubject: Re: Random Tip #2 - Utilizing Whitespace   Random Tip #2 - Utilizing Whitespace EmptyWed Aug 11, 2010 8:15 pm

i want to do that lol. i havent even compiled my own src yet Very Happy
Back to top Go down
http://odstofficalsite.webs.com
Wander
C++ Expert
Wander


Posts : 72
Join date : 2010-08-10
Location : Florida

Random Tip #2 - Utilizing Whitespace Empty
PostSubject: Re: Random Tip #2 - Utilizing Whitespace   Random Tip #2 - Utilizing Whitespace EmptyWed Aug 11, 2010 8:16 pm

Get on it, boy! lol XD start learning. i have an open source section on my website where me and my friend post ideas. not many idea yet, but soon to be more
Back to top Go down
http://letslearncpp.forumstech.com/
DarK_DemoN
»[\...VIP.../]«™ AdminiStratoR
DarK_DemoN


Posts : 584
Join date : 2010-07-20
Age : 31
Location : Hacking Kingdom, USA

Random Tip #2 - Utilizing Whitespace Empty
PostSubject: Re: Random Tip #2 - Utilizing Whitespace   Random Tip #2 - Utilizing Whitespace EmptyWed Aug 11, 2010 8:20 pm

ill make sure i register at your site Very Happy
Back to top Go down
http://odstofficalsite.webs.com
Wander
C++ Expert
Wander


Posts : 72
Join date : 2010-08-10
Location : Florida

Random Tip #2 - Utilizing Whitespace Empty
PostSubject: Re: Random Tip #2 - Utilizing Whitespace   Random Tip #2 - Utilizing Whitespace EmptyWed Aug 11, 2010 8:20 pm

okay sweet Smile
Back to top Go down
http://letslearncpp.forumstech.com/
Sponsored content





Random Tip #2 - Utilizing Whitespace Empty
PostSubject: Re: Random Tip #2 - Utilizing Whitespace   Random Tip #2 - Utilizing Whitespace Empty

Back to top Go down
 
Random Tip #2 - Utilizing Whitespace
Back to top 
Page 1 of 1
 Similar topics
-
» random codes
» Random Tip #3 - Using Comments
» Random Tip #1 - Positioning Set-Brackets
» Random Tip #4 - The camelHump Method

Permissions in this forum:You cannot reply to topics in this forum
1337codez™ :: Programing :: C++ Programinng Basics :: C++ Programing Tools :: C++ Programing Help and Questions-
Jump to: