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

This is a discussion on please help me with this simple do while loop, for heaven's sake within the C++ Programming forums, part of the General Programming Boards category; Hi I have been trying to fix the error for the last half an hour. For heaven's sake, could you ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,529
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 04: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

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