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
    22,304
    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;
    }
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    22,304
    You have the right idea in your original code:
    Code:
    sum += numEntered;
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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