This code won't work. The very first line is already wrong: #include<iostream.h> . Any compiler from the last decade will tell you "include file not found".
At that's just the first of many problems with standard-C++ in your code.
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
Atleast u'll not have to waste time like i did!!!!
How can it be a waste of time when you learn how to do something? You're basically just preemptively doing everyone's homework for them with this code snippet (seeing as how this program was homework, judging by the file comment).
Anyway, the code is filled with assumptions and poor practices. Here are a few of the ones that stick out:>#include
Not standard, becoming more and more scarce as modern compilers start refusing to compile it.
>void main()
main returns int. It always has, even back to the prehistory of C (C++'s primary parent language).
>if (k<=33)
You're making assumptions about the range of long double.
>//register will enhance performance by minimizing access time
In practice, register will probably be ignored by your compiler. Even if this hint is honored, the effect is likely to be detrimental as the compiler is far better at allocating registers than an application programmer. As such, adding restrictions when there's no guaranteed (or even likely) benefit is silly.
>int numArr[10000];
The array size is an unwarranted assumption.
>numArr[10000]=1; //start from end of array.
You mean start by overflowing the array. In an array of 10000 elements, the last accessible index is 9999.
>//numArr[i] is being accessed in this for loop because we have
>made i as register which means the memory is allocated
Um, i is an automatic variable anyway (as is numArr). If you got to this point, it's allocated, regardless of being declared as register or not. Your comment is nonsensical and unnecessary.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
If you are really interested in learning C++ and becoming a good programmer, take all this advice constructively. Tomorrow when you go out to work in the professional world and do these mistakes, no one will point them out to you, they would probably just fire you. So, there's no point becoming all obstinate about your code, you are in-fact lucky that you got your code reviewed by such good programmers and got all this feedback.
Be wise and try to understand every bit of what's given and importantly, don't take your teacher's word as final.
Agni
Practically a Master Poster
655 posts since Dec 2007
Reputation Points: 431
Solved Threads: 116
> Well, i have used this program in visual C++ 6.0.
VC6 is over 10 years old. The world has moved on, and so have the standards for C++.
> And i have n't posted this code without consulting a proper teacher.
Ever hear the adage "those that can, do; those that can't, teach"?
It is our considerable experience which suggests there are a lot of teachers out there who couldn't find their own ass in the dark, nevermind teach C++ (or programming in general) with any degree of competence.
Just because someone who claims to be your teacher has checked the code does NOT make it bug free (Narue trivially proved this to be the case with your array overstep), but your teacher didn't spot that did they?
In the real world (if you hope to program beyond college), your code will be reviewed many many times by lots of people with vastly more experience of programming than either you or your teacher. Mistakes will always be found.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
>Well, i have used this program in visual C++ 6.0. And it works perfectly.
It crashes and burns in Visual C++ 2005 and 2008, but that's after I fix the code to be more standard. Before that it doesn't even compile. I guess you're behind the times. Not a good thing when you're likely to use the more modern versions out in the real world.
>I am a beginner, and so this code has been checked by a proper teacher.
Yes, you are a beginner. And this code may have been checked by a teacher, but certainly not a proper teacher. A proper teacher would have seen the glaring overflow bug.
>Mistakes will always be found.
Yes, and it's preferred that mistakes be found before the code goes live. Because fixing a mistake in production is far more expensive and time consuming than fixing a mistake during development.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401