do while loops

This is a discussion on do while loops within the C++ Programming forums, part of the General Programming Boards category; Hiya - I'm getting very confused with do-while loops, I'm trying to do a more complicated version of this but ...

  1. #1
    hel
    hel is offline
    Registered User
    Join Date
    Dec 2001
    Posts
    3

    do while loops

    Hiya - I'm getting very confused with do-while loops, I'm trying to do a more complicated version of this but I know that if I get the hang of this I can do my propler program!

    The problem is that no matter what number I initially enter it tells me that it is an odd number but then works after that!

    Can anyone explain what I'm doing wrong please - I'm going crazy!

    #include<iostream.h>
    #include<Text.h>
    //using namespace std;
    int main()
    {
    int value;
    cout << "enter even number" << endl;
    cin >> value;

    while (value%2==1) // if odd

    do
    {
    cout << "that is an odd number try again";
    cin >> value;
    }

    cout << endl << "that is correct"; // if even

    return 0;
    }

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    241
    it is do while not while do... change your location of the while

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple thread for loops
    By lehe in forum C++ Programming
    Replies: 12
    Last Post: 03-29-2009, 12:01 PM
  2. Too many loops D:
    By F5 Tornado in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2007, 12:18 AM
  3. recoursion or loops?
    By Mecnels in forum C++ Programming
    Replies: 2
    Last Post: 01-14-2002, 11:09 AM
  4. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 03:28 PM
  5. for loops - newbie q's
    By Narciss in forum C Programming
    Replies: 8
    Last Post: 09-26-2001, 02:44 AM

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