i need help with my c++ <cmath> program

hi guy i need some help writing my c++ program

i need to write something like this and im getting errors
need help
can anyone correct it so i can see how you did that thats the best way for me to learn


#include <iostream>
#include <string>
#include <cmath>
using namespace std;
const double g=9.8;
double CalculateRadius (double T,double X,double Y);
int main()
{
// Input
double angleDeg=0.0;
cout << "Enter angle in Degrees:";
cin >> angleDeg;
while (angleDeg <0.0 || angleDeg >=90.0){
cout << "Degrees?";
cin >> angleDeg;
if (angleDeg <0.0) {cout << "Too low" <<endl;}
if (angleDeg >=90.0) {cout << "Too high" <<endl;}

double velKPH=0.0;
cout << "Enter speed Kilometres Per Hour:";
cin >> velKPH;
while (velKPH <=0.0){
cout << "Kilometres Per Hour?";
cin >> velKPH;
if (velKPH <=0.0) {cout << "Too slow" <<endl;}

// Processing
double angleRad = angleDeg*M_PI/180.0;
double R = (pow(velKPH,2.0)/g)*sin(2.0*angleRad);
double T = R/(velKPH*cos*angleRad);
double X = (velKPH*cos*angleRad)*T;
double Y = (velKPH*sin*angleRad)*T-(0.5(g)(pow(T,2.0));

// Output
cout << "You will fly" <<T<<X<<Y<<R<<endl;

return 0;
}
It would help for us to help you if:

1. You used the code tags to preserve indentation.
2. You tells us more about what's wrong than just "I get errors."
Last edited on
ERRORS


[k_maslon1@mars ~]$ g++ shooting_guy.cpp
shooting_guy.cpp: In function `int main()':
shooting_guy.cpp:30: error: invalid operands of types `double' and `<unresolved overloaded function type>' to binary `operator*'
shooting_guy.cpp:31: error: invalid operands of types `double' and `<unresolved overloaded function type>' to binary `operator*'
shooting_guy.cpp:32: error: invalid operands of types `double' and `<unresolved overloaded function type>' to binary `operator*'
shooting_guy.cpp:32: error: `5.0e-1' cannot be used as a function
shooting_guy.cpp:32: error: expected `)' before ';' token
shooting_guy.cpp:38: error: expected `}' at end of input
shooting_guy.cpp:38: error: expected `}' at end of input
[k_maslon1@mars ~]$
1
2
3
double T = R/(velKPH*cos*angleRad);
double X = (velKPH*cos*angleRad)*T;
double Y = (velKPH*sin*angleRad)*T-(0.5(g)(pow(T,2.0));


I think you forgot the () for cos and sin on these lines. They are functions, but without the (), your implying they are variables that you never declared.

Better formatting of your code will help to spot syntax errors too.
And i need to write a program for my hw
some guy is shooting and i need to calculate: total distance how far he will fly, total time,x distance, y distance.
for input needs to be Angle in degrees and velocity kPH [0,infinity)
for progress:R = (pow(velKPH,2.0)/g)*sin(2.0*angleRad);
T = R/(velKPH*cos*angleRad);
X = (velKPH*cos*angleRad)*T;
Y = (velKPH*sin*angleRad)*T-(0.5(g)(pow(T,2.0));
you mean i have two write like this?
double T = R/(velKPH*(cos)*angleRad);
double X = (velKPH*(cos)*angleRad)*T;
double Y = (velKPH*(sin)*angleRad)*T-(0.5(g)(pow(T,2.0));

you mean i have two write like this?
double T = R/(velKPH*(cos)*angleRad);
double X = (velKPH*(cos)*angleRad)*T;
double Y = (velKPH*(sin)*angleRad)*T-(0.5(g)(pow(T,2.0));


No.


R = (pow(velKPH,2.0)/g)*sin(2.0*angleRad);
T = R/(velKPH*cos*angleRad);
X = (velKPH*cos*angleRad)*T;
Y = (velKPH*sin*angleRad)*T-(0.5(g)(pow(T,2.0));


sin and cos are functions. You called them like so:

sin(number);
cos(number;

Where number is the angle in radians.

You used sin as a function in the first line here, then neglect to use it and cos as functions in the lines that follow.

I suspect you are missing a '}' or two in there too, which is why better formatting practices will help. I think your while loops aren't closed.
Last edited on
ok got it fixed but what about these

shooting_guy.cpp:32: error: `5.0e-1' cannot be used as a function
shooting_guy.cpp:32: error: expected `)' before ';' token
shooting_guy.cpp:38: error: expected `}' at end of input
shooting_guy.cpp:38: error: expected `}' at end of input
thank you
alright got it fixed but still one error
shooting_guy.cpp:32: error: `5.0e-1' cannot be used as a function
i cannot use .5? or 1/2?
You're using it wrong. Multiplication cannot be implied in computer programming.

You cannot represent:

y = 0.5(g);

literally.

You have to write out:

y = 0.5 * g;
ok now everything is correct thank you so much do you think i need to add something to it or my program looks fine?



#include <cmath>
using namespace std;
const double g=9.8;
double CalculateRadius (double T,double X,double Y);
int main()
{
// Input
double angleDeg=0.0;
cout << "Enter angle in Degrees:";
cin >> angleDeg;
while (angleDeg <0.0 || angleDeg >=90.0){
cout << "Degrees?";
cin >> angleDeg;
if (angleDeg <0.0) {cout << "Too low" <<endl;}
if (angleDeg >=90.0) {cout << "Too high" <<endl;}
}

double velKPH=0.0;
cout << "Enter speed Kilometres Per Hour:";
cin >> velKPH;
while (velKPH <=0.0){
cout << "Kilometres Per Hour?";
cin >> velKPH;
if (velKPH <=0.0) {cout << "Too slow" <<endl;}
}

// Processing
double angleRad = angleDeg*M_PI/180.0;
double R = (pow(velKPH,2.0)/g)*sin(2.0*angleRad);
double T = R/(velKPH*(cos(angleRad)));
double X = (velKPH*(cos(angleRad)))*T;
double Y = (velKPH*(sin(angleRad)))*T-(5.0e-1*g*((pow(T,2.0))));

// Output
cout << "You will fly" <<T<<X<<Y<<R<<endl;

return 0;
Topic archived. No new replies allowed.