CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: While loop crash

    Quote Originally Posted by Archetype
    Then I do mean lurk

    As a funny side note - I went to bed right before reading about While loops last night, which is partway through chapter 4. Doh! As soon as I read the correction I opened my book, and saw the proper syntax for a while loop.

    /begin lurking
    Even those of us that have been doing this a while make silly mistakes in our posts here sometimes. It happens.

  2. #17
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: While loop crash


  3. #18
    Join Date
    Jul 2008
    Posts
    12

    Re: While loop crash

    I got it working thanks for the help guys. All i needed to change was <= 3 to !=3. Only thing is now its adding wrong but that should be easy to fix. Adam

    Code:
    #include <iostream>
    using namespace std;
    
    void main ()
    {
        int num1, 
            num2 = 0, 
            total; 
    
            while (num1 != 3)
                {
                total += num2;
                num1++;
                cout << "Please enter a number.\n";
                cin >> num2;
    
                }
    
                cout << total;
    
    }

  4. #19
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: While loop crash

    Quote Originally Posted by blobs
    I got it working thanks for the help guys. All i needed to change was <= 3 to !=3.
    I don't think you did. You got a fix in the very first reply to your post (see post #2), but chose to ignore it...
    Good luck!
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  5. #20
    Join Date
    Jul 2008
    Posts
    18

    Re: While loop crash

    Quote Originally Posted by blobs
    I got it working thanks for the help guys. All i needed to change was <= 3 to !=3. Only thing is now its adding wrong but that should be easy to fix. Adam
    Try:
    Code:
    #include <iostream>
    using namespace std;
    
    void main ()
    {
        int num1 = 0, 
            num2 = 0, 
            total = 0; 
    
      while (num1 <= 3)
      {
    	   cout << "Please enter a number.\n";
    	   cin >> num2;
    	   total += num2;
    	   num1++;
       }
    cout << total;
    }

  6. #21
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: While loop crash

    Quote Originally Posted by dizuane
    Try:
    Code:
    #include <iostream>
    using namespace std;
    
    void main ()
    {
        int num1 = 0, 
            num2 = 0, 
            total = 0; 
    
      while (num1 < 3)
      {
    	   cout << "Please enter a number.\n";
    	   cin >> num2;
    	   total += num2;
    	   num1++;
       }
    cout << total;
    }
    The requirement was for it to execute 3 times.

  7. #22
    Join Date
    Jul 2008
    Posts
    18

    Re: While loop crash

    Yah just caught that.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured