deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think i have coded the program correctly but when I try to run it, it doesnt run...

Can you be more specific about what happens when it "doesn't run"? Does the program not start at all? Does it ask you for a filename but then give an error? Does it get past the filename part and loop forever? Does it not loop at all? Did you try to debug your code? We need more information to help you.

Dont write
using namespace std;
Try without it. It worked on my pc. :-D

You need a newer compiler, dude. Yours is non-compliant with standard C++.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Adding to what sepp2k said, when you say Text foo, it's as if you said char foo[80]. A typedef represents a type, where the name of the typedef fits in the same place that the variable name would in an actual declaration. It's simpler and more consistent to keep the same declaration syntax rules.

nmakes commented: Hmm... Thank you! :D +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The problem seems to have solved itself, but the answer is largely no. There are two ways to reverse a vote/rep:

  1. The voter must do it from their account by navigating to the post and clicking the vote button a second time.
  2. We go into the database, delete the record, and update any statistics manually.

Obviously #2 is to be avoided, so except in outstanding cases, you're the only one who can reverse your votes on a post.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Note that I'm adding to happygeek's answers and directing them at geniusvishal.

No, it is not possible. Even administrators (such as myself) cannot see who is downvoting. The system is designed to be anonymous.

It's possible, given that we do store that information in the database. But there's no interface for it yet, and retrieving the information requires a direct database query by Dani (as she's the only one with that kind of access). So for harrassment cases we can track down guilty parties, if necessary. That's only happened once in the entire history of Daniweb though, so I wouldn't be too worried about it. That's also why an admin interface for searching votes is somewhat low on my priority list.

You have contacted them as they, along with the administrators, read this forum. You can also flag individual posts as bad, which will bring those specific issues directly to the attention of the moderating team (flagged posts appear in a closed forum where the mods can review them and take action as necessary).

You're also welcome to send any of us a private message with concerns you may have. The "no help through PM" rule doesn't apply to issues that might require moderator or admin attention. ;)

Yes, the asp.net forum is being moderated.

"Moderated", as pertains to the question may mean "every post is systematically reviewed" as opposed to what actually happens which is more along the lines of "keeping an eye …

geniusvishal commented: Thank You again. By the way DiHydrogen Monoxide is water... :-) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Traditionally in computer-based fields a degree was mostly useful for your first job. After that your experience and skills would determine marketability, and that's still true more so than in other fields. However, these days a 4 year degree is becoming more and more of a step 1 filter by HR departments. Unless you have a contact on the inside who can recommend you, a degree would help on cold calling.

I have an A.S. degree, but I've been lucky that all of my jobs and offers have been acquired through previous contacts rather than doing foot work. As such, I'm a strong proponent of networking to build a contact list and save yourself the hassle of being just another resume in the stack.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

that code is a bit more advanced

CSV is a bit more complicated, so the code to handle it must also be more complicated.

what if its just a regular csv file, no quotes.

Let's make one thing clear, when you say CSV you imply a format that includes the following restrictions (based on RFC 4180):

  1. The first line may optionally be a header.
  2. Each record is placed on a separate line.
  3. Each record contains one or more fields separated by a single comma.
  4. Empty fields are represented by two adjacent commas.
  5. Each field may optionally be surrounded by double quotes.
  6. If a field contains a newline, comma, or double quote, then the field must be surrounded by double quotes.
  7. Double quotes inside of a field must be escaped by doubling them (eg. "allowed ""'s inside").

So when you say "regular" CSV, the above is what everyone will assume. In my experience the most common CSV feature that's not included is support for embedded newlines.

You can say "simple" CSV, or CSV "without quoting rules", or even "comma delimited" to make it clear that you only support comma delimiters and none of the special rules. However, this also introduces the restriction that you cannot have embedded commas in a field. In my experience, this is often prohibitive to the point where I prefer pipe characters ('|') for simple delimited files because pipes are less likely to be in a field.

what if …

smith32 commented: that help me understand the CSV file and inspirit to learn CSV file format. Thank you a lot. +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

strtok() doesn't respect CSV quoting rules, and as such it's the wrong solution to your problem. You need to actually parse the CSV format and break it down properly, which means either using a library or writing your own parser (not especially difficult, but not trivial either).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are you trying to store the music file itself as a blob, or are you storing a path for the file and relevant metadata? Because the former isn't recommended and the latter is trivial as long as you have a way of extracting the metadata.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Under certain desktop layouts, typically tablets or rotatable displays, the Community button sits beneath the Hardware & Software button. So that, when a pointer hovers over the Hardware & Software button, the first few items on the dropdown menu is obscured by the Community button sitting below the Hardware & Software button.

Usually that's a zoom problem that's easily corrected, but if it's on a tablet and you don't have control over it, a workaround is to go to the home page where there's a list of all top level forums on the right hand column.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you're using LPCWSTR in the first place, you should also be using std::wstring rather than std::string. Then you can just use the c_str() method from std::wstring directly. It's certainly possible to convert the latter into the former, but it's fair to say that not having to do a conversion is the better option if you can manage it:

#include <string>
#include <vector>
#include <Windows.h>

namespace strings {
    std::wstring widen(const std::string& s)
    {
        std::vector<wchar_t> buf(MultiByteToWideChar(CP_ACP, 0, s.c_str(), s.size() + 1, 0, 0));

        MultiByteToWideChar(CP_ACP, 0, s.c_str(), s.size() + 1, &buf[0], buf.size());

        return std::wstring(&buf[0]);
    }
}
CodeAngry commented: You should still consider checking s.empty()... and return a std::wstring() directly. +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you will, explain what "SpecialCost" is, What a "SqlDbType.Int" is and what is the purpose of the zero in the parentheses

Judging by your questions, I'm guessing you aren't using parameterized queries. The first parameter is the column name of your table. The second is the type of the table, and the third is the maximum length allowed for the value. I didn't know the setup of your table, so I made up a column name: SpecialCost. Since the type of the parameter is a fixed size, the size argument is ignored, but it's still required in the constructor call. So I just use 0 since it's the most obvious dummy default.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

' I need to say spclcost = DBNull.Value. But how do I do that?

You don't do that. You use either spclcost or DBNull.Value when assigning the database parameter. For example:

Dim parameter As New SqlParameter("SpecialCost", SqlDbType.Int, 0)

If IsNumeric(txbSpecialCost.Text) Then
    parameter.Value = Convert.ToInt32(txbSpecialCost.Text)
Else
    parameter.Value = DBNull.Value
End If

Then add the parameter to your SqlCommand object's Parameters collection. spclcost never gets assigned DBNull.Value unless you want to define it as type Object, but that would confuse the intention of the code in my opinion.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So what is the correct syntax to assign DBNull.Value to the variable "spclcost"?

You don't do it that way. If the string is empty when you write to the database, use DBNull.Value instead of spclcost.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

For writting quality code you must use proffesional IDE.

I disagree. It's not the quality of the tools that matter, it's the quality of the programmer.

Octet commented: I couldn't agree with you more. +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Does "int32.TryParse()" bring back a True/False answer?

http://msdn.microsoft.com/en-us/library/system.int32.tryparse.aspx

Regarding "DBNull.Value", do I write that as

No, you use it when actually writing to the database. Your title suggests that you're writing to a database, but you're focusing on what looks like validation code that runs first.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

When the user bypasses entering anything within those textboxes (as they should do), what is the correct way to handle the reporting?

If null values are acceptable in the database then you can write DBNull.Value when the string is empty.

Is there a way to determine if the characters within "txbSpecialCost" are Alph or Numeric characters?

Yes, though if you're looking to validate numeric input I'd suggest either a NumericUpDown control rather than TextBoxes, or validate by trying to convert to the numeric type with something like Int32.TryParse().

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Unless you do want to discourage beginner/intermediate programmers to try to help out, I think you might want to take a more patient approach to dealing with them.

In the case of beginners who know close to nothing, won't admit that they know close to nothing, and stubbornly insist that they're neither wrong not clueless, I'd prefer that they didn't help until they have a bit more experience.

You'll notice that the vast majority of beginners who try to help are encouraged. So maybe you should consider why we were giving this one such a hard time. Be sure to read all of his posts for a complete perspective.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Which require stronger social skills Programmer or Network Administration

Having done both, I'd say suck it up and work on your social skills, or find a different field. In all seriousness, social skills are needed as either a programmer or a network admin. If you don't have them and have no intention of developing them, you'll have a very hard time being successful.

From what I've seen of entry level programmer when I was a mail clerk they didn't do to much talking. Just coding in a cubicle.

It may seem that way, especially in organizations that don't do things like pair programming, but communication is paramount unless you're the only programmer and the only client for a project.

ddanbe commented: Well said! +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Serializing objects like that is not safe unless you can guarantee that the class in question is a POD type. In the best case for something like std::string, you'd end up writing addresses pointing to data rather than the data itself. The actual data would be lost and the addresses would be meaningless when deserializing.

You might consider using something like Boost::Serialization, or manually serializing by writing ToString() and FromString() methods in your class, then serializing the string data. Which is better really depends on your needs.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

God forbid you post interesting content that people will like. I guess that's too much work compared to artificially increasing likes with silly things such as sock puppet accounts.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I am not wrong! I put this program in my terminal, and it showed the errors!

Let me be more clear in what I mean by "you're wrong". You're wrong in that what you said to help the OP was wrong in every conceivable way. I have no doubt that you're getting errors on your "terminal", but I also have no doubt that it's because you're at a point in your own education where you have no business trying to help others.

My advice to you is learn before trying to teach.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Look I'm not saying anything bad?

You're not saying anything bad, you're just completely wrong. I suspect that the errors you're getting are due to how you're copying and compiling the code, not anything with the code itself, which is just a snippet and contains exactly one error on the stated 6th line. The problem is that the typedef is incomplete at the point where next is defined, and thus it cannot be used. The solution is to give the structure a proper tag and use that:

typedef struct Node
{
       int ordinalSum;
       int LexemeCode;
       Line Info;
       struct Node *next;
}Node;

Structure tags and typedef identifiers are in different name spaces, so they can both be Node. Easy peasy, but it's still a snippet, so you'll get errors if you try to compile it as if it were a complete program.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Need help

"Help" suggests that you're doing most of the work and others are providing assistance when you get stuck. However, posting nothing but a homework assignment suggests that your definition of "help" is closer to "do it for me". So please provide evidence that you've put in some effort, or our definition of "help" will be to direct you toward books and tutorials for beginners.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

An array of pointers is possible beacuse pointers are similiar to variables.

Pointers are variables, and the values they hold are addresses.

*pt[3] is an array of 3 pointers i.e 3 locations are set aside for the storage of the addresses of 3 variables.

In the context of a declaration, yes. *p[3] is also a valid expression that dereferences the 4th element of an array.

Another added advantage is that we can have variable length arrays.

"Variable length" isn't the term you want, since it has connotations that don't apply (such as being able to grow and shrink the size of an array, or define the size at runtime). I think what you meant was a jagged array, where each sub-array can be of a different size. However, this only applies when taking into account that pointers can be used to simulate arrays. An actual 2D array cannot be defined as a jagged array because there's no way to tell the compiler that you want varying sizes for individual elements.

Pointers to arrays are declared as (*ptr)[4]. I don't understand what is the difference between this definition and the one I gave above.

The first is an array that contains pointers. The other is a single pointer that can point to an array type. It might help if you incorporated the concept of pointers with the concept of types. A pointer is a variable that holds an address, nothing more. There are …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I plan to go to work every weekday, just like the rest of the year. Slightly improved traffic will be a nice change though.

Ketsuekiame commented: Coming up to Easter half term here. I am also looking forward to my journey time reducing by 15 minutes each way ;) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

if I post an error, someone downvotes it and adds as reason <hypothetical>: no, what you suggest is the use of deprecated methods, ... now that I can understand, appreciate and learn from.

Once again, if the voter were interested in providing a reason, he'd use reputation or reply to your post (or a combination of vote/rep and a reply) and explain it. In this particular example, the best approach would be a reply explaining that you used deprecated methods and elaborating with what the modern methods are.

Allow me to offer an alternative example to your hypothetical downvote. Let's say that someone votes negatively, but offers the helpful comment of 'wrong', or 'blah blah'. Forcing a comment doesn't ensure that the comment will be meaningful. Even with rep you'll see a lot of comments that aren't helpful in discerning why the person in question voted.

Your first way does seem cleaner. It would also allow you to "link" your downvotes at a later date should you wish. I tend to favour this model of development, however, I can't see your code so the cost may outweigh the potential benefit.

Agreed. However, looking at the code, a fundamental redesign wouldn't be justified by what still seems like dubious benefit. The only benefit I'm seeing so far in this thread is if the voter provides a meaningful comment on a downvote, one might recognize the problem, agree with it, and learn from the perceived mistake. There are …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Would it be possible to implement a system that requires a sensibly sized comment to be entered before a down-vote is actioned whilst remaining anonymous?

We own the code and designed the system, so it's most certainly possible. ;) I don't dislike the idea, by the way. In a certain sense, I'm playing devil's advocate here just to make sure that if we choose to make a change, it's been fleshed out from all perspectives.

If you're going to downvote someone, you must have a reason as to why. I don't think it's unreasonable to require someone to enter that reason, even if the commenter remains anonymous.

Your logic is selective. If you're going to vote either way, you must have a reason why, right? So why should negative votes be the only ones requiring a comment, anonymous or not? I've gotten upvotes that were just as baffling as your example downvote, yet it's somehow important that only the downvote be explained?

Because you can anonymously downvote without a reason, you could just find all posts by one person and downvote them. If you had to spend time writing out a reason each time (or even copy/pasta) it makes it less worthwhile. In the case of copy/pasta, it would be easy for you (as a moderator) to see and check a complaint of revenge voting.

All true, though a slew of downvotes from a single person as if they went down the list of …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Let's be realistic for a moment and consider the human condition. Since you asked to know who downvoted, specifically, and not who voted in general, it's kind of obvious what the implied intention is. You want to know so that you can accost the voter, find out why they were so impudent as to downvote you, and possibly even strongarm them into reversing it. The more noble members will take the reason to heart and try to avoid similar behavior in the future, but the reality is that the vast majority will be offended and not change their ways, even for perfectly valid and reasonable votes.

I don't really feel strongly one way or another about this issue, but I feel it's important to recognize both the reason for wanting a feature as well as the likely negative effects of implementing it. However, in full disclosure, a bulletpoint near the top of my list of things to do is write an admin page for searching vote records. ;)

that potential is already there. chances are you know, or assume to know, who it was and downvote that person.

Unless that person confirms it, you don't know, you only assume to know. Even I don't know without asking Dani to query the production database. With named downvotes, you're sure, and will probably be less hesitant to go on the offensive. Please don't misunderstand that this is the only reason votes are anonymous, it's just the first possible negative effect …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If the voter were interested in explaining his or her reasoning, they would leave a comment rather than just vote, or reply to the thread in addition to voting. I'm not sure I see the benefit of showing who down votes, given the potential for revenge voting.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's usually recommended that people start with Beej's Guide to Network Programming.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

In Assembly there's not going to be much insight on linked lists, B trees, arrays, etc.

Um...what?

In fact those don't even exist at the bit level.

They don't exist at any level. Data structures are an abstract concept that get implemented using available language features. You can create a linked list, binary tree, etc... using assembly just as readily as in any full featured programming language.

So if we realize that the closer we get to the architecture the lesser the abstraction gets, and that our [...]

It seems like you quickly got off topic and started ranting about something completely different than the title of this thread suggests. What's your point?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is there any chance that a set of rules could be implemented to prevent abuse of the endorsement system?

Given that you can only endorse once per account per favorite forum, it's pretty tedious to abuse the system. You could certainly call all of your friends who have an account and ask them to endorse you, but does that really buy you anything?

The metrics are intended to be viewed as a whole, with endorsements added most recently to provide a view on how people see you as a valued poster in your favorite forums.

  • Account Age: Has this member been around long enough for others to get a good taste of their expertise?
  • Post Count: Are subsequent quality metrics statistically significant?
  • Contributions: Does this member ask more questions (starting discussions) or answer more (reply to discussions, post tutorials, post code snippets, etc...).
  • Favorite Places To Post: Does this member have a broad range of skills and/or interests?
  • Activity Points: How does this member spend their time? Ideally you'd want to see a member posting in articles. Note that moderators tend to have relatively high PM counts due to how the moderation system works (you get a PM automatically when we do just about anything).
  • Up Votes & Unique Members who have voted: How many individual posts have been voted positively and are there a lot of unique voters? This suggests that a lot of people appreciate this member's posts. If the number of unique voters is small …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

you mind i ask where i can put a clrscr command on your codes

How about nowhere? clrscr() is a Turbo Cism, it basically makes your code non-portable for no good reason at all. In fact, you should avoid the entire conio.h library whenever possible.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You could take the easy way out and use a loop to handle removing the blanks, though I suspect your assignment wants recursion to handle everything:

void compact(char *s)
{
    if (!s[0] || !s[1]) {
        // Fewer than 2 characters left in the string
        return;
    }

    if (isspace(s[0]) && isspace(s[1])) {
        // Shift-overwrite the current whitespace character
        for (int i = 0; s[i]; i++) {
            s[i] = s[i + 1];
        }

        compact(s);
    }
    else {
        compact(s + 1);
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

As the titles says I wanna know what are versions of C++ other than Standard C++ and what are the differents between those version if any!

Every compiler offers extensions to both the language and the library, but you can generally say that the different "standards" of C++ are as follows:

  • ARM Standard: Compilers released earlier than 1998. They may or may not conform to some parts of C++98 due to how long it takes to release a standard document. The de facto standard at the time was defined by The Annotated C++ Reference Manual (called the ARM).
  • ISO C++98: The first official international standard. When a compiler says it conforms to C++, it must at least be C++98.
  • ISO C++03: Minor wording changes and fixes to the 1998 standard in 2003.
  • C++0x: Intermediate support between C++03 and C++11 of C++11 features while they were in development.
  • ISO C++11: The final and most current standard released in 2011.

Second question what is contained in the .exe file I'm using Microsoft compiler "Visual Studio 2010 IDE"?

It contains stuff necessary for the OS to load and run your program such as certain variable definitions, data, instructions for executable code, and library references.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I still haven't got my head around pointers which I think is the problem.

Every object reference you used in Java...was a pointer. The only differences are Java references don't use explicit dereferencing operators, and Java references are restricted in terms of things like pointer arithmetic. That may help you conceptually.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's hard to say without knowing the purpose of the Screen class. What is a "screen" in this context? The call to the constructor suggests one of two things:

  1. The Screen object will take ownership of a pointer to the registers created by the caller:

     Screen::Screen(Register* registers, int numRegisters)
         : _registers(registers), _numRegisters(numRegisters)
     { }
    
  2. The Screen object will make a copy of the given "array" (many possible variations):

     Screen::Screen(Register* registers, int numRegisters)
     {
         _registers = new Register[numRegisters];
    
         for (int i = 0; i < numRegisters; i++) {
             _registers[i] = registers[i];
         }
     }
    
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Nonetheless, you shoud add cast to char* at lines 31 and 70 because malloc() and realloc() return argument are of type void*.

C supports implicit conversion both to and from void*. Best practice in C is not to cast, because the cast can hide a legitimate and common error of forgetting to include <stdlib.h>. However, if your personal style is to add the cast, it won't hurt anything as long as you're careful.

In C++ or C meant to be compatible with C++, you must include the cast, because C++ doesn't allow implicit conversion from void*.

tux4life commented: Thanks for including the reason ;) +13
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm using Turbo C++.

Turbo C++ doesn't support standard C++. You'd be wise to upgrade to a compiler that isn't over 20 years old. But if you continue to use Turbo C++, take note that you're stuck with pre-standard C++ and all of the limitations that come with it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

there this code is totally correct

Then you don't need any help...ever, because you refuse to recognize that your code is WRONG. Have a nice day.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

All of you includes are depreciated.

Deprecated, not depreciated. Also, since <iostream.h> and <conio.h> were never standard in the first place, they cannot be deprecated. They're just non-standard.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'll be committing a fix for this display bug shortly. Pending Dani's approval it should be resolved in the next push to production.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Wildcards are interpreted by the shell before your program gets a chance to touch them. If you want them passed as literals, then escape them so that they're not interpreted as wildcards:

$ python ./arch.py install \*
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There is no pass by value when it comes to a function with array as the parameter.

It's the other way around. There's no pass by reference in C, period. When passing an array, you're passing the address as a pointer by value.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Wouldn't it be even more efficient, if you calculated the size of the array inside the functions?

Aside from not being possible without enforcing some kind of structure to the array that allows calculation of its size, calculating something that's not calculated originally would be less efficient.

Since in almost every case, you wouldn't want the array_size to differ from the actual size of the array.

That's not really the function's problem. If the caller lies to it, there's really nothing it can do. Also, it would be more flexible if you don't require the size to match the size of the array because you might want to perform a partial sort:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define N 10

void swap(int *a, int *b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

void bubblesort(int a[], int begin, int end)
{
    for (int i = begin; i < end; i++) {
        int done = 1;

        for (int j = end - 1; j > begin; j--) {
            if (a[j] < a[j - 1]) {
                swap(&a[j], &a[j - 1]);
                done = 0;
            }
        }

        if (done) {
            break;
        }
    }
}

void show(int a[], int n)
{
    for (int i = 0; i < n; i++) {
        printf("%4d", a[i]);
    }

    puts("");
}

int main(void)
{
    int a[N];

    srand((unsigned)time(NULL));

    for (int i = 0; i < N; i++) {
        a[i] = rand() % 100;
    }

    show(a, N);

    /* Sort the two halves …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

define('DB_NAME', 'lol);

Count the single quotes in that line.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm not advocating for an obsessive compulsion to declare variables at the narrowest scope that is humanly possible, as you seem to imply that I do.

That's what I inferred from your example, which is what I believe to be excessive localization of declarations:

cout << "enter a" << endl;
float a = 0.0;
cin >> a;

cout << "enter b" << endl;
float b = 0.0;
cin >> b;

cout << "enter c" << endl;
float c = 0.0;
cin >> c;

The reason I brought it up is because you were offerring it as a superior example to a beginner, who might take that kind of thing to heart and go overboard with it. So I felt a tempering perspective was warranted.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

And if you want to debate the issue, take it up with Herb Sutter, Andrei Alexandrescu and Bjarne Stroustrup.

This reeks of appeal to authority; if you have an argument to make, make it. I've already read anything you're likely to be thinking of from those authors, and it didn't change my mind.

I don't disagree that declaring variables reasonably close to the beginning of their logical lifetime is a good idea. I do disagree that variables should always be declared immediately before their first use, which is what it seems like you're advocating. The former when used judiciously can greatly enhance code clarity compared to always declaring variables at the top of the function (the other extreme, which I'll mention again I'm not advocating), but the latter can make code harder to read and understand by forcing you to switch between declaration and execution mindsets.

Let's take your replacement for the original code and reorganize a few declarations to make it read better (in my opinion). There are three general chunks of related code: the input of operands, the calculation, and output of the result: Untitled38
It's obvious that a, b, c are related, so lumping them together makes more sense than interspersing them between the input statements. Technically they can be viewed as having a lifetime of the entire function, and therefore it makes sense to put them at the top.

The calculation is a separate logical unit, but still uses …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Since you hash define NUM_ITEMS, you don't really need to pass it to functions.

What if the caller wants to use something other than NUM_ITEMS without redefining it? Passing the size provides greater flexibility, and just because you can do something doesn't mean you should. You can use NUM_ITEMS all over creation, but that doesn't mean it's a good idea.