Help me please to understand what is wrong

Write your question here.

it is my second program. need to calculate runway of an airplain by formula:
length = speed^2/acceleration*2.

This is my program.
#include <iostream>

using namespace std;

int main()
{



{
int v,length;
//v is speed in meters per second, length is runway length of the airplain.
double a;
// a is acceleration of the airplain.

cout << "Enter_v\n";
cout <<"v_is_speed_of_an_airplain\n";
cout << "Press_enter_key_after_each_variable\n";

cin >> v;
cout << "Enter_a \n";
cout << "a is acceleration\n";
cin >> a;
length = (v^2) / (2*a);
cout << "that means the legnth will be: ";

cout << "Display the mininum runway length\n";

return 0;
}
what is wrong? why it does not work? please help me to understand my mistake.

Thanks.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

int main()
{
        std::cout << "Enter the speed of the air plane: ";
        int v ;
        std::cin >> v;

        std::cout << "Enter its acceleration: " ;
        double a ;
        std::cin >> a;

        // note: ^ is the bitwise xor operator
        // https://msdn.microsoft.com/en-us/library/3akey979.aspx
        const double length = (v*v) / (2*a) ;

        // print out the computed length
        std::cout << "that means the minimum runway legnth will be: " << length << '\n' ;
}
Please use code tags.
http://www.cplusplus.com/articles/jEywvCM9/

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
#include <iostream>

using namespace std;

int main( )
{
{ // random curly brace
	int v,length;
	//v is speed in meters per second, length is runway length of the airplain.
	double a;
	// a is acceleration of the airplain.

	cout << "Enter_v\n";
	cout <<"v_is_speed_of_an_airplain\n";
	cout << "Press_enter_key_after_each_variable\n";

	cin >> v;
	cout << "Enter_a \n";
	cout << "a is acceleration\n";
	cin >> a;
	length = (v^2) / (2*a); // ^ is actually the bitwise XOR operator
	cout << "that means the legnth will be: ";

	cout << "Display the mininum runway length\n"; 

	return 0;
}


To get v2, you could either do:
v * v
OR
pow(v, 2)
http://www.cplusplus.com/reference/cmath/pow/

I would also recommend to make v and length a double, as the user could enter floating point values.
Last edited on
Topic archived. No new replies allowed.