Re: <Help> Simple Pause Needed.

From: Jonathan Mcdougall (jonathanmcdougall_at_DELyahoo.ca)
Date: 10/02/03


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



Relevant Pages

  • Re: How can I pass a multidimensional array as a ref parameter in func
    ... Arrays are always passed by reference even if you omit 'ref' before the ... > public int ReadFile(ref ushortnArray, string sFname, int w, int h) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: c file reading
    ... Robert Gamble wrote: ... variables or arrays) please? ... int main { ... serve you well to pick up a good reference on C programming, ...
    (comp.lang.c)
  • Re: c file reading
    ... variables or arrays) please? ... int main { ... Robert Gamble ... serve you well to pick up a good reference on C programming, ...
    (comp.lang.c)
  • Re: Question about passing by value
    ... in types like int, char, etc rather than like arrays (note that this is ... where they are passed by reference). ...
    (comp.lang.cpp)
  • RE: Indirect reference causes statistical function to throw up a #
    ... Statistical functions tend to deal with arrays more often than traditional ... reference cell, how can I combine it into a reference that would make sense ... to the OFFSET function as a single-cell range for the FORECAST ... INDIRECT gathers info to form a cell reference, ...
    (microsoft.public.excel.worksheet.functions)