Thread: Help accumilative variables

  1. #16
    Registered User BuzzBuzz's Avatar
    Join Date
    Feb 2009
    Posts
    89
    ....not quite what I meant.

    Do you think that code would do what you want it to? Try putting the program together and run it. It's better to learn through trying. Don't be afraid of getting errors and weird outcomes, if you don't make the mistakes you won't learn how to fix and avoid them.

  2. #17
    Registered User
    Join Date
    Feb 2009
    Posts
    83
    yea but I don't actually have those numbers and I don't know how to get the positive and then get the total of them

  3. #18
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by walkonwater View Post
    yea but I don't actually have those numbers
    So create them.

  4. #19
    Registered User
    Join Date
    Feb 2009
    Posts
    83
    yea but am I positioning my if statement wrong?

  5. #20
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by walkonwater View Post
    yea but am I positioning my if statement wrong?
    That depends on whether you want to add to your positive/negative totals before or after you add 0.4 to the value.

  6. #21
    Registered User
    Join Date
    Feb 2009
    Posts
    83
    Quote Originally Posted by tabstop View Post
    That depends on whether you want to add to your positive/negative totals before or after you add 0.4 to the value.
    I want it to look like this:
    -2.3 -1.9 -1.5 -1.1 -0.7 -0.3 0.1 0.5 0.9 1.3 1.7 2.1 2.5 2.9
    Sum of negative values: __
    Sum of positive values: __

  7. #22
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by walkonwater View Post
    I want it to look like this:
    -2.3 -1.9 -1.5 -1.1 -0.7 -0.3 0.1 0.5 0.9 1.3 1.7 2.1 2.5 2.9
    Sum of negative values: __
    Sum of positive values: __
    So look at the list. Do you want to add to the positive/negative totals before or after you add 0.4 to the value?

  8. #23
    Registered User
    Join Date
    Feb 2009
    Posts
    83
    Quote Originally Posted by tabstop View Post
    So look at the list. Do you want to add to the positive/negative totals before or after you add 0.4 to the value?
    Well I know, after. I don't know the correct space

    Code:
    while (value <= 2.9) {
        cout << value << " ";
        value = value + .4;
        if (0 < value)
        total = value
        cout << "Sum of negative values" << value
        else 
        cout << "Sum of positve valies" << value
    I know this isnt right but can you just tell me what to do.

  9. #24
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by walkonwater
    I know this isnt right but can you just tell me what to do.
    I have been, although that presumes you've been reading. You need to create numbers to hold the positive and negative totals. (You created value, right?) You need to add the value to the appropriate total, using the if-statement to help you figure out which.

  10. #25
    Registered User
    Join Date
    Feb 2009
    Posts
    83
    Quote Originally Posted by tabstop View Post
    I have been, although that presumes you've been reading. You need to create numbers to hold the positive and negative totals. (You created value, right?) You need to add the value to the appropriate total, using the if-statement to help you figure out which.
    So do I need to create a double or float? Can you tell me what I have wrong in my code.

  11. #26
    Registered User
    Join Date
    Feb 2009
    Posts
    83
    Code:
    #include <iostream>
    
    int main () {
         double value, total;
    value = -2.3;
      while (value <= 2.9) {
        cout << value << " ";
        value = value + .4;
        if (0 < value)
        total = value
        cout << "Sum of positve values" << value
        else 
        cout << "Sum of negative valies" << value
    This is my code and what else do I need and what is WRONG?

  12. #27
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You said you wanted separate positive and negative totals. So create them. And then, use them.

    Every statement needs a semicolon (especially "total = value").

    You can't print your totals until your loop is finished. So don't try to print your totals until after your loop.

  13. #28
    Registered User
    Join Date
    Feb 2009
    Posts
    83
    Quote Originally Posted by tabstop View Post
    You said you wanted separate positive and negative totals. So create them. And then, use them.

    Every statement needs a semicolon (especially "total = value").

    You can't print your totals until your loop is finished. So don't try to print your totals until after your loop.
    I can't do this. I have been working on it for about 7-9 hours.

  14. #29
    Registered User
    Join Date
    Feb 2009
    Posts
    83
    can you seriously just put how it should look so I can learn by visuals. I am completely lost.

  15. #30
    Registered User BuzzBuzz's Avatar
    Join Date
    Feb 2009
    Posts
    89
    Quote Originally Posted by walkonwater View Post
    I can't do this. I have been working on it for about 7-9 hours.
    Quote Originally Posted by walkonwater View Post
    can you seriously just put how it should look so I can learn by visuals. I am completely lost.
    If you're that stuck then you need to go back over what you have learned with regard to loops. Try making simpler but similar programs that do the sort of thing you want the example to do. Once you've got the component parts figured out and actually understand them then you can work on putting it all together.

    It is unlikely that you are going to get the program written for you as it appears to be a homework assignment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  2. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  3. esbo's data sharing example
    By esbo in forum C Programming
    Replies: 49
    Last Post: 01-08-2008, 11:07 PM
  4. Craps Program with Local Variables
    By tigrfire in forum C Programming
    Replies: 12
    Last Post: 11-09-2005, 09:01 AM
  5. Replies: 6
    Last Post: 01-02-2004, 01:01 PM