Thread: wont output my data table

  1. #1
    Registered User
    Join Date
    Feb 2015
    Posts
    10

    wont output my data table

    Project Golfer.cpp




    so when you enter the number 99 its supposed to quit the program and it wasnt so i fixed that 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 so i put a goto statement in and now it wont output my data table. not sure how to fix it please help!
    Attached Files Attached Files
    Last edited by blukacs3609; 02-26-2015 at 07:08 PM. Reason: edited the file

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,611
    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;
    		} 
    	}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A problem with output of a two-dimensional table
    By chihuyu in forum C Programming
    Replies: 1
    Last Post: 08-13-2014, 10:42 PM
  2. Printing a table of strings and data?
    By Godfearn in forum C Programming
    Replies: 5
    Last Post: 01-10-2012, 12:14 PM
  3. Table not showing data
    By vaibhav in forum C# Programming
    Replies: 1
    Last Post: 07-16-2006, 05:20 AM
  4. Inputting data from a table of properties
    By cassius in forum C Programming
    Replies: 1
    Last Post: 06-01-2005, 11:22 AM
  5. Printing out a data table in different sequences
    By TheDudeAbides in forum C Programming
    Replies: 2
    Last Post: 07-20-2003, 12:06 AM