View Full Version: my very first program

C++ Learning Community > C++ Help > my very first program


Title: my very first program
Description: on my own!!


666kennedy - February 9, 2007 01:48 PM (GMT)
hey, with thanks to your help, i have the confidence to start writing my own program,

i thought i would make it useful, so one of my friends is having trouble with formulas so i thought i would use a simple "speed distance time" formula to get me started, anyway i have gone through it writing what i think is right, but im having a little bit of trouble, as im having loads of errors and i would like to know if im completely off the track with this...


CODE
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
#pragma hdrstop

//-------------------------------------------------------------------

using namespace std;

int main (void)
{
   float SPEED;                  // variables s, d, t,
   float DISTANCE;
   float TIME;
   
   
   
   cout << " please specify which variable you need ( SPEED, DISTANCE, TIME ): ";
   
   if cin >> SPEED;
      {
          cout << " please enter distance ( metres ) : ";
          cin >> DISTANCE;
          cout << " please enter time ( seconds ) : ";
          cin >> TIME;
          cout << " speed is " << ( DISTANCE / TIME ) << " metres per second ";
      }
   else if cin >> DISTANCE;
        {
          cout << " please enter speed ( m/s ) : ";
          cin >> SPEED;
          cout << " please enter time ( seconds ) : ";
          cin >> TIME;
          cout << " distance is " << ( SPEED * TIME ) << " metres ";
         
        }
   else cin >> TIME;
        {
             cout << " please enter speed ( m/s ) : ";
             cin >> SPEED;
             cout << " please enter distance ( metres ) : ";
             cin >> TIME;
             cout << " time is " << ( DISTANCE / SPEED ) << " seconds ";
        }
   getch();

return 0;

}
//-------------------------------------------------------------------



thanks, i might have used if else statements wrong as i just learned them today!




Hosted for free by InvisionFree