I started learning C++ 3 days ago. I try and do at least an hour of programming everyday and lots of programming problems. So i tried to solve this problem
Quote:Braking distance of some vehicle at speed of 100 km/h is equal to 48 meters. Assuming that other conditions has not been changed (friction, tyres, breaking system and so on) one can estimate that the breaking distance is proportional to the square of the speed of the vehicle. Please compute the vehicle's breaking distance for a given speed X.
by writing this program:
/* title: C++ programming excercises date 11/08/2010*/#include<iostream> #include<cmath> //lets me use sqrt functionusing std::cin;using std::cout;using std::endl;using std::domain_error;using std::sqrt;int main(){ cout<<"Please enter your current speed"<<endl; unsigned short int speed; //tried this as float speed but no luck cin>>speed; //test to see if speed value is correct if(speed<=0||speed>250){ throw domain_error("not a valid speed"); } float breakingDistance=.0048(*sqrt(speed)); cout<<"Your breaking distance is: "<<breakingDistance<<endl; system("pause"); return 0;}
I am getting the following errors in VS 2010 professional
Quote:
Error 1 error C2100: illegal indirection C:\c++programs\acppchapter3\acppchapter3\main.cpp 27 1 acppchapter3
Error 2 error C2064: term does not evaluate to a function taking 1 arguments C:\c++programs\acppchapter3\acppchapter3\main.cpp 27 1 acppchapter3
3 IntelliSense: expression must have (pointer-to-) function type c:\c++programs\acppchapter3\acppchapter3\main.cpp 27 25 acppchapter3
4 IntelliSense: more than one instance of overloaded function "sqrt" matches the argument list: c:\c++programs\acppchapter3\acppchapter3\main.cpp 27 32 acppchapter3
I have read over the c++ reference of sqrt and other examples that popped up after a google search. What am i doing wrong?
Thanks.