Thread: Small program using "if" and some variables assistance.

  1. #31
    Registered User
    Join Date
    Jan 2012
    Posts
    16
    Code:
    do {
            cout << "\n";
            cout << "Input s, u, v, a and t: (0 for unknown)\n";
            cin >> s >> u >> v >> a >> t;
            cout << "Which variable do you need?\n";
            cin >> var;
    
            if ( var=="v" && u!=0 && a!=0 && t!=0 )
                {
                    float v=u + a*t;
                    cout <<"Final velocity = "<< v <<" m/s\n";
                }
            else if ( var=="v" && u!=0 && a!=0 && s!=0 )
                {
                    float v=sqrt( u*u+2*a*s );
                    cout <<"Final velocity = "<< v <<" m/s\n";
                }
            else if ( var=="s" && u!=0 && t!=0 && a!=0 )
                {
                    float s=u*t + 0.5*a*t*t;
                    cout << "Displacement = "<< s <<" m\n";
                }
            else if ( var=="s" && a==0 )
                {
                    float s=0.5*(u + v)*t;
                    cout << "Displacement = "<< s <<" m\n";
                }
            else
                {
                cout << "Insufficient/Invalid Input!\n";
                }
    
            }while (1);

  2. #32
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Reserve an invalid value as "unknown," eg -1.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 12-07-2011, 06:23 PM
  2. How to reference variables inside an "asm"?
    By User Name: in forum C Programming
    Replies: 9
    Last Post: 06-22-2010, 01:26 PM
  3. small programming confusion in "C"...
    By GajananDon in forum C Programming
    Replies: 1
    Last Post: 06-20-2010, 10:11 PM
  4. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  5. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM