Keep geting return code 255

I keep geting return code 255.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  // Hidrostatic Pressure Calculator

#include <iostream>
#include <sstream>
#include <string>
using namespace std;
const double g = 9.81;

int main ()
{
    string input;
    float Ro = 0;
    float h = 0;
    
    cout << "Density: " << endl;
    getline(cin, input);
    stringstream(input) >> Ro;
    if(Ro < 0)
    {
        cout << "Invalid Input" << endl;
        return -1;
    }
    
    cout << "Hight: " << endl;
    getline(cin, input);
    stringstream(input) >> h;
    if(h < 0)
    {
        cout << "Invalid Input" << endl;
        return -1;
    }
    
    double HidrostaticPressure = Ro * g * h;
    if(HidrostaticPressure < 0);
    {
        return -1;
    }
    
    cout << HidrostaticPressure << endl;
    
    
    return 0;
}
Why don't you just use cin to take the input? Is it for defensive purpose?
1
2
3
4
5
6
7
8
if(HidrostaticPressure < 0); //←Look at the last character
{
    return -1;
}
//Equivalent to:
if(HidrostaticPressure < 0)
    ; //That way it is more obvious
return -1; //Braces makes no difference here 
Although main() returns an int, that doesn't mean that the operating system will return the full integer value to calling process. On UNIX systems you really only get the least significant byte. Try returning 1 instead of -1.
Topic archived. No new replies allowed.