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