| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
To All My for (loops) Helpers!!!
I thought you guyz might want to see some progress instead of always answering my questions. I thought I might show you some results of your efforts. I answered the following question all by me self, thanks to your guyz previous help.
Quote:
Here's my solution Code:
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
int i = 0;
float B_S[12] = {0.0};//Books Sold
float B_C = 15.0;//Book Cost
float B_T = 0.0;//Sum of Books Sold
string M[13]={"Jan","Feb","March","April","May","June","July","Aug","Sept","Oct","Nov","Dec"};
for ( i = 0; i <12; i++)
{
cout<<M[i]<<": ";
cin>>B_S[i];
B_T += B_S[i];
}
cout<<B_T * B_C<<" Dollars in sales for the year "<<endl;
system("PAUSE");
return 0;
}
I know this isn't a question, I just thought this would be relevant to all the ppl who help me on a regular basis to show them that their efforts aren't in vain. <Thanks>If some one has a faster || just a quicker way, please share... Side note : to all the ppl that are like "SHUT UP WITH THE FOR LOOPS" this will be the final for(loop) post for me, I promise. ---Official Member of The Itsacon Fan Club--- ![]() |
|
#2
|
||||
|
||||
|
Great program, but just to be a whiner:
I just like to whine ![]() Well done, my young padawan! ![]()
__________________
This is my code. Is it not nifty? "The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools." ---Douglas Adams Join the Itsacon fanclub! Zero Tolerance: Spammers banned so far: 564
![]() |
|
#3
|
||||
|
||||
|
Don't worry I'm the type of person that likes constructive criticism. As long as you don't have thin skin that is the best way to improve yourself. I use to work in construction, and you can take the constructive right out of criticism because that's all you got, like it or not. I have noticed that the regular ppl of the world(other than construction ppl) put things much nicer
And yes I agree, conserving memory in a simple program this small, yes it doesn't make a difference, but like you say, and not even with just micro controllers, is that once you get to programming on a much larger scale it becomes more important to conserve memory when you can, and if you don't set out some good practices you are going to waste all the memory you have and still have half your program left to write. The story of my life again ![]() By the way thanks for that link too. Side Question : What is your opinion on Hungarian Notation and in your job is it even necessary, I have read mixed reviews on it so far. ---Official Member Of The Itsacon Fan Club--- ![]() |
|
#4
|
||||
|
||||
|
Quote:
First time I heard of it, had to go to Wikipedia to find out what it was. In my experience, giving your variables clear names is important, but only for variables that stay around longer. Loop variables (such as the famous i for for loops) should be as short as possible ('loopvariableforsecondloopincalculatefunction' does not make your code any clearer, especially when used to index arrays ), whereas a temporary variable is very clear if you call it 'temp'.For instance, when I retrieve info from a database, the result is usually called 'result', and the subsequent rows are called 'row'. This is ok, since they all have a very temporary scope in which I use them. Any place where I use them, I can still see the code where they were first assigned. (This is a pretty good guideline when deciding the scope in which you use a variable). If you're keeping track of the number of errors occuring during the entire execution of a program, naming that variable 'numberOfErrors' is much clearer then 'e', since someone reading this at the end of your code has no idea whether 'e' is an error, or 2.718281828... If you feel hungarian is a clear way to do this, it might be good to learn it. Same goes for several other naming methods. It's more important to be consistent than which convention you use. here is a good list of the pros and cons of Hungarian. |
|
#5
|
||||
|
||||
|
Well I don't know how Wikipedia defined Hungarian notation, but its basically putting an identifier before your variable that way at any point in your code you will always know of what type it is. int, float, pointer and so on. Its a Microsoft thing mostly but someone had mentioned to me if I was programming in C/C++ and had plans of programming for windows at all I would need to not only get familiar with it but also start to use it.
Heres a link that shows you a little bit of the examples of Hungarian notation. http://web.umr.edu/~cpp/common/hungarian.html But ya, I just wanted someones opinion on that, and being that you are in programming and you have never heard of it. I don't think I'll have to worry about it too much. ![]() |
|
#6
|
||||
|
||||
|
Quote:
Me, I don't need it because I name all my variables accurately enough to know what type they need to be. Well, usually, at least. I start rewriting code and using variables for different functions it gets messy ![]()
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips. ![]() |
|
#7
|
||||
|
||||
|
Ya, I have gotten mixed reviews from different ppl, myself. Some say that its good practice and some say it is only a way to confuse yourself later, because eventually through the course of your code it will become less and less accurate, therefore making it difficult to read and understand by others. So, that was my opinion too, just make your variables the easiest for ppl to understand.
![]() |
|
#8
|
||||
|
||||
|
To the smart programmer, there are two ways of writing code:
Other programmers may go for option 3, which is code that can be updated and edited by any code monkey, leaving you without a job.... |
|
#9
|
||||
|
||||
|
lol, Itsacon. Well, I hope in time I can be the number one, because right now Im more on the side of number two.
. A comment on number three, I totally agree with that but it seems that all the ppl I have talked to so far are like you need other ppl to be able to read your code, but I think the third one is best, at least when your coding for money that is. So I guess the longer I'm doing this the better I will know what to do when the time comes. ![]() |
|
#10
|
||||
|
||||
|
If your employer, or direct boss, has any knowledge of coding you will not get away with being number 2. Number 2 and 3 only work in small projects where you are the only programmer (or the only good one
) If you think you can make yourself indispensable by being the only one who understands your code, be careful.. You might think you are a l33t coder but your boss might just think someone else is a cheaper l33t coder ![]() I wish their was a good way to rate software, like a quality assurance grade.. There are so many ways to implement something, but so many ways are inferior which can not be seen by anyone until you really dig into the code.. |
|
#11
|
||||
|
||||
Yeah, option 3 is usually the best (I try to go for that one too), especially since most software projects are done by more than one person at the same time...Note, it is of course possible to combine options 1 and 3, but the programmer with that kind of patience and skill hasn't been born yet ![]() |
|
#12
|
||||
|
||||
|
TY guys for all your insight, although Im not a programmer yet, information about the working arena is good to know, before I get involved in it. I'm from a totally different proffession all together so the change will be drastic I'm sure.
and little tips like that are good to know in advanced. ![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > To All My for (loops) Helpers!!! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|