Looping

This is a discussion on Looping within the C++ Programming forums, part of the General Programming Boards category; How do you get a certain part of code to keep looping till a string a characters are entered?? <tag> ...

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    8

    Looping

    How do you get a certain part of code to keep looping till a string a characters are entered??

    <tag>
    cout << "Enter a value:" << endl;
    cin >> a;
    cout << "Enter the desired opperation:" << endl;
    cin >> f;
    cout << "Enter a value:" << endl;
    cin >> b;
    <\tag>

    ok in case you can't tell i'm a super newbie at this. This ^ is supposed to be a calculator and it works but it want to know how to make this part repeat untill the word "calculate " is entered. I know about the "for" statement but i'm not sure how or if it applies here.

  2. #2
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    You could use a for loop, but a while loop would be a considerably simpler to implement.

    And the code tags are [ CODE ] and [ /CODE ].

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    9
    Code:
    do
    {
    cout << "Enter a value:" << endl;
    cin >> a; 
    cout << "Enter the desired opperation:" << endl;
    cin >> f;
    cout << "Enter a value:" << endl;
    cin >> b;
    cout << "Calculate? /n";
    cin <<calculate;
    } while( calculate ==  ) //the loop continues untill the while is broken
    If you had a qestion that said press one or two and you wanted it to repeat if you press two:

    Code:
    do
    {
    cout << "press 1 or 2 /n";
    cin >> answer;
    }while(answer ==2);
    if you press anything other than 2 it stops

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. wierd looping effect after exporting 3ds to .x annimation
    By Anddos in forum Game Programming
    Replies: 3
    Last Post: 01-06-2009, 01:43 PM
  2. problems with prototype function looping
    By dezz101 in forum C Programming
    Replies: 5
    Last Post: 04-29-2008, 07:03 AM
  3. looping went berserk
    By miryellis in forum C Programming
    Replies: 7
    Last Post: 09-21-2004, 02:59 PM
  4. Looping questions
    By Peyote in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2003, 12:01 AM
  5. looping and input
    By Kinasz in forum C Programming
    Replies: 2
    Last Post: 03-17-2003, 07:12 AM

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