Thread: problem with the loop

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    4

    problem with the loop

    #include <iostream.h>
    #include <conio.h>
    #include <stdio.h>
    #include <windows.h>
    #include <time.h>


    #define sleep Sleep
    int main(void)
    {





    float grav = 9.80;
    float mass, acceleration,weight,mew, time,finalvelocity,initialvelocity, speed,gravity, force, torque, forcen, friction, forcep, distance, mass2;
    int poop;
    int butt;
    int finger;
    int me;













    while(poop)
    {

    Sleep(5000);

    {


    int i;

    for (i = 0; i < 50; i++)
    putchar ('\n');



    cout<<endl<<"What would you like to find?"<<endl;
    cout<<"(1) Acceleration or Speed"<<endl;
    cout<<"(2) Weight or Fw "<<endl;
    cout<<"(3) Mass "<<endl;
    cout<<"(4) Force "<<endl;
    cout<<"(5) Mew and the forces of friction "<<endl;
    cout<<"(6) Exit the program"<<endl;


    cout<<":";
    cin>>poop;



    }

    {


    int i;

    for (i = 0; i < 50; i++)
    putchar ('\n');

    if (poop == 1)
    {

    cout<<"Which would you like to find?"<<endl;
    cout<<"(1) Acceleration "<<endl;
    cout<<"(2) Speed "<<endl;
    cout<<":";
    cin>>butt;

    if (butt == 1)
    {

    cout<<"What is the final velocity in m/s?:";
    cin>>finalvelocity;
    cout<<endl<<"What is the intial velocity in m/s?:";
    cin>>initialvelocity;
    cout<<endl<<"What is the elapsed time in seconds?:";
    cin>>time;

    acceleration = (finalvelocity - initialvelocity)/time;

    cout<<"The acceleration is : "<<acceleration;

    cout<<" m/s^2"<<endl;
    }
    }



    if (butt == 2)
    {

    cout<<"Enter the total distance : ";
    cin>>distance;
    cout<<endl<<"Enter the total time : ";
    cin>>time;

    speed = distance/time;
    cout<<"The speed is : "<<speed;
    cout<<" m/s"<<endl;
    }





    if (poop == 2)
    {

    cout<<"What is the mass in kilograms?:";
    cin>>mass;

    weight = mass * grav;
    cout<<"The weight in Newtons is: "<<weight<<endl;

    }

    if (poop == 3)
    {

    cout<<"What is the weight in newtons?:";
    cin>>weight;
    mass = weight / grav;
    cout<<"The mass of the object in kilograms is: "<<mass<<endl;

    }

    if (poop == 4)
    {

    cout<<"Which would you like to do?"<<endl;
    cout<<"(1) Force and acceleration on bodies of known weight Force = Fw*a/g"<<endl;
    cout<<"(2) Newton's second law of motion Force = ma"<<endl;
    cout<<"(3) Law of universal gravitation Force = G*m1*m2/(d)^2"<<endl;
    cout<<":";
    cin>>finger;

    if (finger == 1)
    {

    cout<<"Enter the weight (Fw):";
    cin>>weight;
    cout<<endl<<"Enter the acceleration :";
    cin>>acceleration;
    cout<<endl<<"Enter the force of gravity :";
    cin>>gravity;

    force = weight*acceleration/gravity;

    cout<<"The force is "<<force;
    cout<<" newtons"<<endl<<endl<<endl;

    }

    if(finger == 2)
    {

    cout<<"Enter the mass :";
    cin>>mass;
    cout<<endl<<"Enter the acceleration :";
    cin>>gravity;

    force = mass*acceleration;

    cout<<"The force is "<<force;
    cout<<" newtowns"<<endl<<endl<<endl;
    }

    if(finger == 3)
    {

    cout<<"Enter the gravitational constant :";
    cin>>gravity;
    cout<<endl<<"Enter the mass of the first body :";
    cin>>mass;
    cout<<endl<<"Enter the mass of the second body :";
    cin>>mass2;
    cout<<endl<<"Enter the distance between their centers of mass :";
    cin>>distance;
    cout<<endl<<endl;

    force = gravity*(mass*mass2)/(distance*distance);

    cout<<endl<<"The force is "<<force;
    cout<<" newtons";

    cout<<endl<<endl;
    }



    }

    if (poop == 5)
    {

    cout<<endl<<"What would you like to do?"<<endl;
    cout<<"(1) Find Mew (the coefficient of friction)"<<endl;
    cout<<"(2) Find the force of friction "<<endl;
    cout<<"(3) Find the normal force "<<endl;
    cout<<"(4) dummie"<<endl;
    cout<<":";
    cin>>me;

    if(me == 1)
    {

    cout<<endl<<"Enter the force of friction :";
    cin>>friction;
    cout<<endl<<"Enter the normal force :";
    cin>>forcen;

    mew = friction/forcen;

    cout<<endl<<"The coefficient of friction is "<<mew<<endl<<endl;
    }

    if(me == 2)
    {
    cout<<endl<<"Enter the coefficient of friction :";
    cin>>mew;
    cout<<endl<<"Enter the normal force :";
    cin>>forcen;

    friction = mew*forcen;

    cout<<endl<<"The frictional force is "<<friction<<endl<<endl;
    }




    if(me == 3)
    {

    cout<<endl<<"Enter the frictional force :";
    cin>>friction;
    cout<<endl<<"Enter the coefficient of friction :";
    cin>>mew;

    forcen = friction/mew;

    cout<<endl<<"The normal force is "<<forcen;
    cout<<" newtons";//it should display answer after this part of the program runs... but it shows it after the screen clears.. and i am not seeing what is causing it. I would like it to loop back to the main option menu after displaying my answer
    }
    if(me == 4)
    {

    cout<<endl<<"you are a dummie!!!";

    }



    }


    if(poop == 6)
    {

    break;
    }


    }
    }




    }

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    add code tags to make that readable

    with no indents it is too much of a mess to follow
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    87
    IF you added code tags it would be a lot easier to read it but from a fast glance it seems to me that the while loop tests poop which has not been assigned a value yet... consider the use of a do while or set poop equal to something.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Addition problem in loop
    By murjax in forum C Programming
    Replies: 3
    Last Post: 07-01-2009, 06:29 PM
  2. validation problem in a loop (newbie question)
    By Aisthesis in forum C++ Programming
    Replies: 11
    Last Post: 05-10-2009, 10:47 PM
  3. For Loop Problem
    By xp5 in forum C Programming
    Replies: 10
    Last Post: 09-05-2007, 04:37 PM
  4. Loop problem
    By Tesnik in forum C++ Programming
    Replies: 29
    Last Post: 08-23-2007, 10:24 AM
  5. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM