Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5430
Number of posts: 16951

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
finding this hard/annoyingly brain demanding...logically Posted by Assist_ark on 3 Jul 2012 at 4:54 PM
Hey guys,
First ever post here. and must say, I hope to learn and be of help to others on this forum.

As the topic suggest, I'm kinda finding the code below rather annoyingly confusing logically (Accelerated C++ (annoying examples or whaat)). The logic behind it makes me think way too much. It's from a book and this is the second chapter. This is a snippet of the actual code.

for (int r = 0; r != rows; ++r) {
						//row=5; col=
		string::size_type c = 0;

		// invariant: we have written `c' characters so far in the current row
		while (c != cols) {

			// is it time to write the greeting?
			if (r == padr + 1 && c == padc + 1) {
				cout << greeting;
				c += greeting.size();
			} else {

				// are we on the border?
				if (r == 0 || r == rows - 1 ||
				    c == 0 || c == cols - 1)
					cout << "*";
				else
					cout << " ";
				++c;
			}
		}

		cout << endl;
	}

Question is: Since I'm finding this kinda confusing, does that mean I'm not cut out to be a programmer? Asking because, I understand the code, just don't see the point. Why the author decides to use the method he's using. I'm always finding myself going through the code line by line, to get what its doing. But at the same time, it is easy.

The bolded is the bit that's pissing me off. So many logic-ors maybe. Really don't know.
Report
Re: finding this hard/annoyingly brain demanding...logically Posted by Gorris on 25 Jul 2012 at 10:43 AM
Just because you find the code confusing doesn't mean you aren't meant to be a programmer. I am a computer programming major and I think the way he wrote the code is very confusing.

The thing about programming is that there are so many different ways to write a program you just have to find you style.

Report
Re: finding this hard/annoyingly brain demanding...logically Posted by Gorris on 25 Jul 2012 at 10:45 AM
Just because you find the code confusing doesn't mean you aren't meant to be a programmer. I am a computer programming major and I think the way he wrote the code is very confusing.

The thing about programming is that there are so many different ways to write a program you just have to find you style.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.