Error Help!!!

This is a discussion on Error Help!!! within the C++ Programming forums, part of the General Programming Boards category; we have only learned while loops. That is why I am so confused....

  1. #16
    Registered User
    Join Date
    Feb 2009
    Posts
    83
    we have only learned while loops. That is why I am so confused.

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,618
    In that case, use a while loop like this instead of a for loop:
    Code:
    int i = 1;
    while (i <= n) {
        // Insert code to request and read in user input and compute the sum
        // ...
        ++i;
    }
    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. #18
    Registered User
    Join Date
    Feb 2009
    Posts
    83
    I have this code:

    Code:
    numValues = 0;
       
      while (numValues < 5) { 
      
        numValues++;
            
        cout << "Enter value " << numValues <<  ": ";
        cin >> numEntered;
    But I don't know how to make the sum after this. Could you just help me STILL (sorry) PLEASE? With a cherry on top?

  4. #19
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,618
    You have the right idea in your original code:
    Code:
    sum += numEntered;
    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

  5. #20
    Registered User
    Join Date
    Feb 2009
    Posts
    83
    Thank you so much! I have it and I don't know what I did differently from the time before, but hey it works and thank you again. Seriously!!

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21