Thread: please help me with this simple do while loop, for heaven's sake

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    254

    please help me with this simple do while loop, for heaven's sake

    Hi

    I have been trying to fix the error for the last half an hour. For heaven's sake, could you please help me? Please do. Thanks a lot.

    When I run the code the screen just starts scrolling continuously.

    Code:
    #include <iostream>
    #include <cstdlib>
    
    using namespace std;
    
    int main()
    
    {
        float m, a, f;
        char v;
    
        do
        {
            cout << "enter mass: ";
            cin >> m;
    
            cout << "enter acceleration: ";
            cin >> a;
    
            f = m*a;
    
            cout << "force is: " << f << endl;
    
            cout << "do you want another calculation? press y/n";
            cin >> v;
        }
    
        while (v != 'n');
    
        system("pause");
    }
    I'm an outright beginner. Using Win XP Pro and Code::Blocks. Be nice to me, please.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Yes, it will do that if you type in anything other than a single letter to your "again?" prompt.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    254
    So sorry, Salem. I was stupid I was entering letters where I should have used numbers. Otherwise the code is fine. Thanks for helping with some many queries. You are really nice.
    I'm an outright beginner. Using Win XP Pro and Code::Blocks. Be nice to me, please.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Heaven is $25,000
    By SniperSAS in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 04-25-2006, 10:45 AM
  2. The Return of Discussions for the sake of Kermi3
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 08-15-2002, 05:55 PM
  3. for old times sake......
    By Aran in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 06-10-2002, 12:13 PM
  4. Will you vote for the sake of voting?
    By mithrandir in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 01-27-2002, 05:09 PM
  5. Programmers Heaven
    By Witch_King in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 08-10-2001, 02:12 PM