Click to See Complete Forum and Search --> : HELP PLEASE!!! C++!!!!


redline
09-12-2001, 11:33 PM
I am writing a program for a class that I am taking and cannot figure out why it is not working. Please help.


#include <iostream.h>
#include <math.h>


int main()
{
float distance_to_target;
float velocity_of_projectile;
float angle_to_fire;
float final_distance = 0;
void radians(float&);
void distance(float, float, float, float&);
void distcheck(float, float, int);
int attempt = 5;

attempt--;
while(attempt != 1)
{
cout<<"Enter the distance to the target:"<<endl;
cin>>distance_to_target;
cout<<"Enter the angle to fire (in degrees):"<<endl;
cin>>angle_to_fire;
radians(angle_to_fire);
cout<<"Enter the velocity at which to fire the projectile:"<<endl;
cin>>velocity_of_projectile;
distance(distance_to_target, velocity_of_projectile, angle_to_fire, final_distance);
distcheck(distance_to_target, final_distance);

attempt--;
}

cout<<"You are out of time. Game Over."<<endl;

return 0;
}

void radians(float& angle_to_change)
{
float PI = 3.14159265;

angle_to_change = (angle_to_change * PI) / 180;
}

void distance(float distance_to_target, float velocity_of_projectile, float angle_to_fire, float& final_distance)
{
final_distance = (pow(velocity_of_projectile,2) * (sin((2 * angle_to_fire))) / 32.2)
cout<<final_distance<<endl;
}

void distcheck(float distance_to_target, float final_distance, int& attempt)
{
float check = (distance_to_target * 0.01);
float check_total_plus = (check + distance_to_target);
float check_total_minus = (distance_to_target - check);
float miss;
if(final_distance <= check_total_plus && final_distance >= check_total_minus)
{
cout<<"You have entered the correct data. The target is destroyed."<<endl;
attempt = 1;
}
else
{
if(final_distance < check_total_minus)
{
miss = (check_total_minus - final_distance);
cout<<"You have missed the target. Target remains."<<endl;
cout<"Target missed by: -"<<miss<<" meters."<<endl;
cout<<"You have "<<attempt<<" attempts left."<<endl;
}
else if(final_distance > check_total_plus)
{
miss = (final_distance - check_total_plus);
cout<<"You have missed the target. Target remains."<<endl;
cout<"Target missed by: +"<<miss<<" meters."<<endl;
cout<<"You have "<<attempt<<" attempts left."<<endl;
}

}

}

Any help would be appreciatted.

TIA

redline

unlstorm
09-12-2001, 11:46 PM
I just ran gcc and here's what it told me was wrong with your program. I don't really want to look at the code much further. So you can go from here.

-Tony

> gcc test.cpp
test.cpp: In function `int main ()':
test.cpp:12: too few arguments to function `void distcheck (float,
float, int)'
test.cpp:27: at this point in file
test.cpp: In function `void distance (float, float, float, float &)':
test.cpp:47: parse error before `<'
test.cpp: In function `void distcheck (float, float, int &)':
test.cpp:70: invalid operands of types `const char[20]' and `float' to
binary `operator<<'
test.cpp:77: invalid operands of types `const char[20]' and `float' to
binary `operator<<'

redline
09-13-2001, 09:23 AM
I figured it out...thanks though! =)

redline

Ben Briggs
09-14-2001, 10:11 AM
Originally posted by unlstorm:
<STRONG>I just ran gcc and here's what it told me was wrong with your program. I don't really want to look at the code much further. So you can go from here.

-Tony

&gt; gcc test.cpp
test.cpp: In function `int main ()':
test.cpp:12: too few arguments to function `void distcheck (float,
float, int)'
test.cpp:27: at this point in file
test.cpp: In function `void distance (float, float, float, float &)':
test.cpp:47: parse error before `&lt;'
test.cpp: In function `void distcheck (float, float, int &)':
test.cpp:70: invalid operands of types `const char[20]' and `float' to
binary `operator&lt;&lt;'
test.cpp:77: invalid operands of types `const char[20]' and `float' to
binary `operator&lt;&lt;'</STRONG>

The reason you got this response from gcc is because you were using gcc :). This is a C++ program and won't compile with a C compiler. Try compiling again with g++ and see what errors you get (too late now, but just for your future reference).