Re: <Help> Simple Pause Needed.
From: Jonathan Mcdougall (jonathanmcdougall_at_DELyahoo.ca)
Date: 10/02/03
- Next message: cbing: "Character to number conversion"
- Previous message: Mike Wahler: "Re: [OT, link] unsure how to implement MFC CArray with class"
- In reply to: Jonathan Mcdougall: "Re: <Help> Simple Pause Needed."
- Next in thread: Jonathan Mcdougall: "Re: <Help> Simple Pause Needed."
- Reply: Jonathan Mcdougall: "Re: <Help> Simple Pause Needed."
- Reply: da Vinci: "Re: <Help> Simple Pause Needed."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 2 Oct 2003 13:46:29 -0400
> >3) too much comment is like not enough
>
> I hate it when things walk a fine line between good and bad! When I
> first started, I did not like using comments. Mainly because these
> programs are so small and simple. I know they would be needed if I was
> working within a group. So I try to make sure to comment a lot or else
> I wouldnt put any in! Maybe I am over doing it? :-)
Yeah, things like
while ( good_or_bad != 0 )
{
cout << "\n\n\nEnter product number (1-5): ";
cin >> prod_num;
good_or_bad = Check_Number(prod_num);
} // Ends Inner While
You know, it is _clear_ that the bracket ends this while. Or better :
return 0;
} // Ends Main
This was actually funny :)
> >4) learn about arrays and vectors
>
> Very soon!
Be careful with them though. I suggest you take a look to std::vector
before arrays, since arrays are error-prone, but I suppose your
teacher knows what she's doing.
>
> ><personal opinion>
> >take the habit of naming the variables even on declaration,
> >it makes things clearer for everybody
> ></personal opinion>
>
> which variables? The ones that are being passed in or the ones that
> will be used for the variables coming in?
Both (if I understand correctly) :
// variables named
void f(int a, int b);
int main()
{
f(1, 2);
}
// ditto
void f(int a, int b)
{
}
> >take the habit of defining one variable per line and
> >to comment each of them. "various program functions" is not
> >very clear imo :)
>
> Does it matter how "long" the code is? I know when it is compiled, it
> will be the same size regardless of how much white space you use in
> the source. There are no draw backs or professional "no-no's" about
> doing things line by line instead of grouping?
No. Depending on the company standards, you will do things differently,
but for programs like that, try to make it as clear as possible.
> >non portable, be careful. A system without 'cls' will do
> >nothing. On my system, 'cls' from the command prompt formats
> >the disk without warning. its a good thing I did not run it :)
>
> Is there a portable way to clear a screen without using a mass of endl
> or \n's?
No. C++ can be used in toasters, you know.
> >mmm.. what about an array or a std::vector here (or even a std::map)?
> >If you didn't learn about them, that's ok, but know that it would
> >be a lot simpler.
>
> Your speaking Greek again. :-) I am vaguely familiar with Arrays and
> plan to tackle them next.
Mmm... if you have a choice, forget arrays right now.
http://cplus.about.com/library/weekly/aa050102e.htm
Or have a Google on std::vector. Do not stop on details like
the weird std:: notation. Try to understand the whole.
Post questions here if you don't understand.
> >Every case should look like these 3 : calling a function or two,
> >but that's it. If not, well.. it makes it harder to understand.
>
> Very true. The problem I ran into when thinking of what I could put
> into functions is that I do not know how to do reference or pointers
> yet. According to the professor, without one of those I can only pass
> one value out of a function.
It does not matter whether you pass by reference or by value. But
actually, you are right. It would be a bit more complicated
to seperate that one.
What would be interesting is to keep that program and to work on
it as your knowledge increases, tweaking it and making it look
right.
> >When something can have two values meaning 'ok' or 'bad', use a bool
> >which can have the values 'true' or 'false' :
> >
> >bool b = true;
> >b = false;
>
> So would this be good to use as a continue type statement?
>
> bool continue;
> continue = false;
>
> while (continue == false) {
> cout << "Do you want to continue(Y/N)?";
> cin >> continue;
>
> if (continue == 'Y')
> continue = true;
> else
> continue = false;
> }
Could be, except that you use 'continue' as a char and a boolean,
but you understand. Personaly, something like
do
{
cout << "Do you want to continue(Y/N)?";
cin >> continue;
} while ( std::toupper(continue) != 'Y' );
If you are not familiar with this version of while, you can
stay with the preceeding one, it is quite good. Or try this
while ( true ) // infinit loop
{
cout << "Do you want to continue(Y/N)?";
cin >> continue;
if ( std::toupper(continue) == 'Y' )
break; // exits the loop
}
which gets rid of a variable.
> Thanks for the ideas and help. This is obviously a tight-knit
> community and glad to be apart of it.
Hehe.. depends on the people.
Jonathan
- Next message: cbing: "Character to number conversion"
- Previous message: Mike Wahler: "Re: [OT, link] unsure how to implement MFC CArray with class"
- In reply to: Jonathan Mcdougall: "Re: <Help> Simple Pause Needed."
- Next in thread: Jonathan Mcdougall: "Re: <Help> Simple Pause Needed."
- Reply: Jonathan Mcdougall: "Re: <Help> Simple Pause Needed."
- Reply: da Vinci: "Re: <Help> Simple Pause Needed."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|