Thread: Question Assistance

  1. #1
    Registered User
    Join Date
    Jun 2013
    Posts
    3

    Question Assistance

    Hi there! I'm new to C Programming and am taking a class that is an extra-departmental requirement for my major (meteorology).

    I need a little assistance on a question that is part of my latest lab assignment dealing with arrays.

    The question asks for the values to be stored in array nums after the following code is executed:

    Code:
    i = 1;
    nums [0] = 1;
     do {
      
        nums[i] = 2 * nums[i - 1];
        i++;
    
     }while (i < A_SIZE);
    Being that nums[0]=1 is given and the A_SIZE is 10, I got the result 1,2,4,6,8,10,12,14,16,18 but was told that was incorrect by my professor. I think I'm just making a silly mistake, but would appreciate any guidance in helping me to figure this out.

    Thanks!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Notice that the expression is 2 * nums[i - 1], not 2 + nums[i - 1].
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2013
    Posts
    3
    Quote Originally Posted by laserlight View Post
    Notice that the expression is 2 * nums[i - 1], not 2 + nums[i - 1].
    Thanks for the speedy reply! I tried again and this is what I got: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512

    From looking back at the loop, it appears that is correct?
    Last edited by tcweather; 06-25-2013 at 11:48 AM.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    looks right to me given the code you are showing. is your code there really what the assignment requires?

    since the problem is small, do it by hand and record the results

  5. #5
    Registered User
    Join Date
    Jun 2013
    Posts
    3
    Quote Originally Posted by dmh2000 View Post
    looks right to me given the code you are showing. is your code there really what the assignment requires?

    since the problem is small, do it by hand and record the results
    Yeah it was just one question out of many. I followed her suggestion to not type it out as she wanted us to do it by hand.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. in need of a little assistance
    By unknown2007 in forum C Programming
    Replies: 8
    Last Post: 11-02-2011, 07:05 AM
  2. Need a little assistance.
    By drakenathaniel in forum C++ Programming
    Replies: 4
    Last Post: 04-12-2009, 05:07 PM
  3. need ur assistance
    By baby_me in forum C Programming
    Replies: 3
    Last Post: 06-21-2006, 01:47 PM
  4. Need some assistance
    By gcpatton in forum C++ Programming
    Replies: 2
    Last Post: 02-19-2006, 08:50 PM
  5. Need some more assistance
    By Thantos in forum Windows Programming
    Replies: 6
    Last Post: 08-14-2003, 12:13 PM