then i noticed that if you dont hit the green its supposed to loop back to a certain point but it was going to far back
Wait, it went too far back? In the original code, you wrote the top of that while loop near the beginning of the program. The program is supposed to go back to the line with the condition on it, test the condition, and then execute the code in the body (again).
so i put a goto statement in
Well, that's wrong. Why didn't you just move out the code that wasn't supposed to execute in the loop?
and now it wont output my data table. not sure how to fix it please help!
Well the table code needs to be put in the loop too. That's my guess. It wouldn't make sense for the table to be printed after you hit the pin, for example, with the way the instructions sound.
Anyway, I moved some code around. You'll notice the goto is now missing. Is this close to what you want?
Code:
// B.Lukacs EGR 111 Project Golfer Feb 12 2015
/* This program asks the user for the distance to the pin and the depth of green
(both in yards) */
/* The program asks the user for an integer club number from 2 to 10 where 10
is the pitching wedge */
/* If the user enters an invalid number, the program prints a warning and asks
for the club number again*/
// The program asks the user for a swing type from 1 to 4 (quater to full swing)
/* The program reads from a file that contains the constants for the following
equations */
//
// club angle (degrees) = a1 + b1 * 0.85 * clubnumber
// club length (inches) = a2 + b2 * 1.05 * clubnumber
// club speed (yards/s) = 1.1 * (a3 +b3 + swingnumber) * (clublength/40)^2
//
/* The program determines the distance the ball travels, how far from the pin
it lands, and whether it hits the pin or not */
//
// The program determines how far the ball travels using the following formula
//
/* distance = club speed^2 sin(2 * club angle in radians)/g
where (g) is 32.2 ft/s^2 */
/* The program outputs a table showing the club used, the swing number,
the distance the ball travels, the distance the ball lands from the pin,
and "YES" if the ball lands on the green, or else "NO" */
/* If the ball does not hit the green the program asks for another club number
and swing speed */
// If the club number 99 is entered, the program ends
using namespace std;
#include <iostream>
#include <windows.h>
#include <math.h>
#include <fstream>
#include <iomanip>
int main()
{
float clublength, clubangle, clubspeed, a1, b1, a2, b2, a3, b3;
int clubnumber, swingtype, swingnumber, error, dist, hitdist, greendepth;
const float g = 32.2 / 3.0, PI = 3.14159;
bool hit;
string hg;
ifstream infile("C:\\EGR 111\\golf.txt");
if (infile) {
infile >> a1 >> b1 >> a2 >> b2 >> a3 >> b3;
}
cout << "Input the distance to the pin in yards: ";
cin >> dist;
cout << "Input the depth of the green in yards: ";
cin >> greendepth;
while (hit == false)
{
do
{
cout << "Input a club number from 2 to 10 <10=wedge> or 99 to "
<< "quit :";
cin >> clubnumber;
if (clubnumber == 99)
{
system("CLS");
Sleep(500);
cout << "Thank you have a nice day";
return 0;
}
cout << "Input swing number from 1 to 4 <quater to full>: ";
cin >> swingnumber;
if (swingnumber >= 1 && swingnumber <= 4)
{
if (clubnumber >= 2 && clubnumber <= 10)
{
clubangle = a1 + b1 * 0.85 * clubnumber;
clublength = a2 + b2 * 1.05 * clubnumber;
clubspeed = 1.1 * (a3 + b3 * swingnumber)
* pow((clublength / 40), 2);
}
}
cout << endl;
cout << endl;
hitdist = (pow(clubspeed, 2) * sin(2 * (clubangle * PI / 180))) / g;
if (hitdist - dist <= 10 && hitdist - dist >= 10)
{
hit = true;
hg = "YES";
}
else
{
hit = false;
hg = "NO";
}
error = abs(dist - hitdist);
// Output results for the distance the ball is hit
cout << "Club Swing Distance<yds> Error<yds> Hit"
<< endl;
cout << "======================================================="
<< endl;
cout << left << fixed << setprecision(4) << setw(9) << clubnumber
<< setw(10) << swingnumber << setw(18) << hitdist << setw(15)
<< error << setw(3) << hg << endl << endl;
} while (clubnumber <= 2 && clubnumber >= 10);
cout << endl;
cout << endl;
}
}