How To?

hk3008

Distinguished
Jan 29, 2012
43
0
18,580
so I have two funtions how do I make them both work in the same .cpp file when I combine them kinda like run through one and another
//************************************************************************
#include <iostream>
using namespace std;


int GenerateID()
{
static int s_nID = 0;
return s_nID++;
}

int main()
{
std::cout << GenerateID() << std::endl;
std::cout << GenerateID() << std::endl;
std::cout << GenerateID() << std::endl;
return 0;
}
//************************************************************************



and
-------------------------------------------------------------------------------------------



//************************************************************************


//************************************************************************
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;


float GetTargetDistance(); // Target's Dist
float CalcWinningRange( float ); // Range to Win
float GetLauncherAngle(); // Angle of Projectile
float DegreesToRadians( float ); // Radian Conversion
float GetProjectileVelocity(); // Projectile Velocity Formula
float CalcProjectileDistance( float, float ); // Projectile Dist Calc
void PrintSummary( int, float, float, float, float); // User Output

int main()
{
float targetDistance = 0.0;
float winningRange = 0.0;
float launcherAngle = 0.0;
float ProjectileVelocity = 0.0;
float launcherRadians = 0.0;
float ProjectileDistance = 0.0;
bool hit = false;

targetDistance = GetTargetDistance();

winningRange = CalcWinningRange(targetDistance);

for(int shotNumber = 1; shotNumber <= 5; shotNumber++)
{

launcherAngle = GetLauncherAngle();

ProjectileVelocity = GetProjectileVelocity();

launcherRadians = DegreesToRadians(launcherAngle);

ProjectileDistance = CalcProjectileDistance(launcherRadians, ProjectileVelocity);

PrintSummary(shotNumber, targetDistance, launcherAngle,
ProjectileVelocity, ProjectileDistance);

if ( fabs(ProjectileDistance - targetDistance) <= winningRange )
{
hit = true;
break;
}
}

if ( hit == true )
cout << "Congrats You Win!\n";
else
cout << "To Bad Better Luck Next Time!\n";

return 1;
}

//************************************************************************
// Funstion to Get Target Dist
float GetTargetDistance()

{
float distance = 0.0;

while ( distance <= 0.0 )
{
cout << "\nTarget distance"
<< "\nIn feet: ";
cin >> distance;
}

return distance;
}

//************************************************************************
// Function to get launch Angle
float GetLauncherAngle()

{
float angle = 0.0;

while ( angle <= 0.0 || angle >= 90.0 )
{
cout << "\nThe launcher angle"
<< "\nEnter degrees: ";
cin >> angle;
}

return angle;
}

//************************************************************************
// Function to get Velocity
float GetProjectileVelocity()

{
float velocity = 0.0;

while ( velocity <= 0.0 )
{
cout << "\nThe Projectiles velocity "
<< "\nEnter Projectile velocity: ";
cin >> velocity;
}

return velocity;
}

//************************************************************************
// Function to Calc Winning Range
float CalcWinningRange( float targetDistance )

{
return (targetDistance * 0.001);
}

//************************************************************************
// Radian Converter
float DegreesToRadians( float launcherAngle )

{
return (launcherAngle * 3.14159265 / 180.0);
}

//************************************************************************
// Distance Calc
float CalcProjectileDistance( float radians, float velocity )


{
return ((velocity * velocity) * sin(2 * radians) / 32.2);
}




//************************************************************************
// Primary User Output
void PrintSummary( int shotNumber, float targetDistance, float launcherAngle,
float ProjectileVelocity, float ProjectileDistance)

{
cout << "\n***********************************************************\n"
<< "Shot Number: (" << shotNumber << ") Looks like your running out!" << endl
<< "Target Distance: " << targetDistance << endl
<< "Launcher Angle: " << launcherAngle << endl
<< "Projectile Velocity: " << ProjectileVelocity << endl
<< "Projectile Distance: " << ProjectileDistance << endl;

if ( ProjectileDistance <= targetDistance )
cout << "\nYou missed by: "
<< targetDistance - ProjectileDistance
<< " feet, Better luck next time!\n";
else
cout << "\nYou over shot by ( "
<< ProjectileDistance - targetDistance
<< " ) feet, Try Again!\n";
cout << "***********************************************************\n";
}
 

theDanijel

Distinguished
May 4, 2011
74
0
18,590


You need to leave just one main function. A program has to have an entry point.
 

hk3008

Distinguished
Jan 29, 2012
43
0
18,580
so woujld Imake it where there was jsut one int main() then connect them all with { and } at the begining or end, or should I float the the results together having it print a summery at the end?