Hypotenuse Calculation Problem

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

#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;

int main()
{
    int x;   //position of x-axis
    int y;   //position of y-axis
    int A;   //square A + square B
    int V;   //resultant vector
    
    A = (x * x) + (y * y);
    V = sqrt ( A );
    cin>> x;
    cin>> y;
    
    cout<< V << "\n";   //output of resultant vector
    cin.get();
    return 0;
}


Hello everyone.This is my first year in computer engineering and we will have C++ in the next semester.However, i am trying to learn it myself..Here is my problem:

I am trying to calculate hypotenuse by giving to x and y different values.DEV C++ compiled it but when the dos screen is opened, i write two different values such as 3 and 4 (here the result must be 5), the windows closes itself.Can someone check where is the error?
Last edited on
Firsly, read x and y BEFORE calculating A!
Secondly, write cin.get() twice at the end.
Thirdly, i advise use
double V;
V = sqrt((double)A);
Thank you guys.It works now.Just an other question that i could not find the answer by seraching.What does "double" command for?
Is a data type for double precision floating point numbers http://www.cplusplus.com/doc/tutorial/variables/
Topic archived. No new replies allowed.