Thread: New to C++, help with code

  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    1

    New to C++, help with code

    Hey guys I'm new to c++ and I was wondering if anyone could help me with my code? I need to make a code that can do the Pythagorean theorem with fractional components. I made a code that can do the theorem but I'm not sure how to do the fractional part. When ever I enter a fractional number in, the program assumes I'm giving values for both a and b instead of just one here is my code.
    Code:
    #include <iostream>#include <math.h>
    #include <cmath>
    
    
    using namespace std;
    
    
    int main ()
    {
      
        float a, b, c;
        cout << "Optimal Driving Distance Calculator \nPlease input the distance of east:";
        cin >> a;
        cout << "Please input the distance of north:";
        cin >> b;
        
    
    
        c = a*a +b*b;
        c=sqrt(c);
    
    
        cout <<"The optimal driving distance is " << c << '.' << endl;
    
    
        system ("pause");
     
    }
    Thanks for you help!

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    As written, you will need to input decimal numbers. Entering in stuff like 1/4 isn't going to work without more programming. If your compiler has C++11 support, you can try using the ratio class, or program something similar yourself.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-19-2012, 01:58 PM
  2. Replies: 1
    Last Post: 03-10-2010, 11:28 AM
  3. producing c/c++ code from flowcharts,pseudo code , algorithims
    By rohit83.ken in forum C++ Programming
    Replies: 3
    Last Post: 02-20-2008, 07:09 AM
  4. Having trouble translating psudeo-code to real-code.
    By Lithorien in forum C++ Programming
    Replies: 13
    Last Post: 10-05-2004, 07:51 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

Tags for this Thread