Thread: Quick Understanding Question

  1. #16
    Registered User
    Join Date
    Apr 2007
    Posts
    42
    Do you think that will be fine? It seems like he would have made it clearer if that was the case. Right? I am not too sure... I am very new at this.

  2. #17
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    Quote Originally Posted by leopardforest@g View Post
    I am not challenging you. But I dont understand why I have to do that? What tells you that you have to calculate it outside of the loop? Am I missing something?
    When you calculate an average, it's easier (but not necessary) to compute the sum, and only then divide by the number of elements, once. BTW, you've written the function to assume that the number of elements is 5. You could pass the number of elements as another argument, and then divide by whatever it is.

  3. #18
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    Quote Originally Posted by leopardforest@g View Post
    Do you think that will be fine? It seems like he would have made it clearer if that was the case. Right? I am not too sure... I am very new at this.
    If you did the loop using a pointer (say named salesp), it would be initialized to sales, then incremented to sales+1, then sales+2, ... and for each value of salesp the corresponding number would be *salesp (instead of *(sales + i)).

  4. #19
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by robatino View Post
    > robatino: Read the assignment.
    Forgot about that. But it's possible that what the instructor meant was for the loop to use a pointer, and not an int, for the variable.
    I doubt it. Write it; tell me that the instructor expected someone to recognize that end condition considering what we have seen so far.

    [edit]Well, it's not horrible; but it seems to me a stretch.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM