Small program using "if" and some variables assistance.

This is a discussion on Small program using "if" and some variables assistance. within the C++ Programming forums, part of the General Programming Boards category; Code: do { cout << "\n"; cout << "Input s, u, v, a and t: (0 for unknown)\n"; cin >> ...

  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
    Posts
    23,010
    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.

Page 3 of 3 FirstFirst 123
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, 02:26 PM
  3. small programming confusion in "C"...
    By GajananDon in forum C Programming
    Replies: 1
    Last Post: 06-20-2010, 11: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

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