New to C++, help with code

This is a discussion on New to C++, help with code within the C++ Programming forums, part of the General Programming Boards category; Hey guys I'm new to c++ and I was wondering if anyone could help me with my code? I need ...

  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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,526
    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, 10: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, 06: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, 05:05 PM

Tags for this Thread


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