Ok heres the problem ( and no laughing at my code!! )
I need it to change the value of the strokedistance to the holedistance when the strokedistance makes the holedistance less than zero.
Any suggestions, ideas, tips, and it doesnt have to be specific to my problem maybe just to my code , would be appreciated.

int main()

{
	char Club =' ';
	char Choice =' ';
	int StrokeCount = 0;
	int StrokeDistance = 0;
                int HoleDistance = 280;
	
	
	
srand(int(time(0)));

cout << " Would You Like To Play? Press [Y] to Continue [N] to Exit "<<endl;
cin >> Choice;
   

cout << endl;

cout << endl;


Choice = toupper(Choice);

while ( Choice == 'Y')

{ 



do

{
    if (StrokeDistance > HoleDistance && HoleDistance != StrokeDistance)
      {
          StrokeDistance = HoleDistance;

       }

	HoleDistance = HoleDistance - StrokeDistance;
	
cout <<"You are " << HoleDistance <<" metres away from the Hole " << endl;
	
	cout << endl;

	
	cout << "Select Club [D]river [I]ron [P]utter :  " << endl;
	cin >> Club;
	cout << endl;

	Club = toupper(Club);


	
	switch (Club)

		
	{
		
	case 'D':  
	
	             StrokeDistance = 80 + rand() % (120 - 80 + 1);

            StrokeCount = StrokeCount + 1;
		
						
	              break;
			
	
	case 'I':   
		StrokeDistance = 24 + rand() % (36 - 24 + 1);
					                          StrokeCount = StrokeCount + 1;

			
                                 break;


		
	case 'P':	                  
		StrokeDistance = 8 + rand() % (12 - 8 + 1);

		StrokeCount = StrokeCount + 1;
				
								break;

	
	default: 	    StrokeCount = StrokeCount + 1;

		cout << " Air Swing 0 Metres Travelled "<<endl;
                        	                            				               cout << endl;

		break;

	
}	
	

cout <<"The ball travelled " << StrokeDistance <<" metres "<< endl;
				cout << endl;
		
}	
while (HoleDistance <=280 && HoleDistance >= 1 && HoleDistance != StrokeDistance );

		
	
	
	
if (HoleDistance <1  || HoleDistance <0)
{
	HoleDistance = 0;
	cout <<" Congratulations the Ball is in the Hole!!! " << endl;	
				cout << endl;
                		}


}

system("pause");

		return 0;
}

Nobody laughs at nobody's code. At least nobody who remembers that they were also new to this once.
What does this program do now?

#include <iostream>
#include <ctime>
using namespace std;
int main()

{
    char Club =' ';
    char Choice =' ';
    srand(time(0));

    cout << " Would You Like To Play? Press [Y] to Continue [N] to Exit "<<endl;
    cin >> Choice;
    cout << endl;
    cout << endl;
    Choice = toupper(Choice);
    while ( Choice == 'Y')
    { 
        int StrokeCount = 0;
        int StrokeDistance = 0;
        int HoleDistance = 280;

        do
        {
            cout <<"You are " << HoleDistance <<" metres away from the Hole " << endl;
            cout << endl;
            cout << "Select Club [D]river [I]ron [P]utter :  " << endl;
            cin >> Club;
            cout << endl;
            Club = toupper(Club);
            switch (Club)
            {
            case 'D':  
                StrokeDistance = 80 + rand() % (120 - 80 + 1);
                StrokeCount = StrokeCount + 1;
                break;

            case 'I':   
                StrokeDistance = 24 + rand() % (36 - 24 + 1);
                StrokeCount = StrokeCount + 1;
                break;
    
            case 'P':	                  
                StrokeDistance = 8 + rand() % (12 - 8 + 1);
                StrokeCount = StrokeCount + 1;
                break;

            default: 	    
                StrokeCount = StrokeCount + 1;
                cout << " Air Swing 0 Metres Travelled "<<endl;
                cout << endl;
                break;
            }	
            cout <<"The ball travelled " << StrokeDistance <<" metres "<< endl;
            if ( StrokeDistance > HoleDistance )
            {
                StrokeDistance = HoleDistance;
            }
            HoleDistance = HoleDistance - StrokeDistance;
            cout << endl;
        }	
        while ( HoleDistance > 0 );

        HoleDistance = 0;
        cout <<" Congratulations the Ball is in the Hole!!! " << endl;	
        cout << endl;

        cout << " Would You Like To Play? Press [Y] to Continue [N] to Exit "<<endl;
        cin >> Choice;
        cout << endl;
        cout << endl;
        Choice = toupper(Choice);

    }
    system("pause");
    return 0;
}

Another tip: If there is a setting in your code editor to replace Tab characters with spaces, set it on. Then your code will not get messy when you post it inside

tags.

Its showing a strokedistance that is greater than the holedistance i cant figure out how to change it so that the last distance is = to the hole distance making it zero, been trying and trying and grrrrrrrrrring at it but its still not doing what i want it to do lol

Did you try compiling and running my code?

Did you try compiling and running my code?

yes but it is still showing the strokedistance as greater than the holedistance with the last choice, I have the following code after the while statement which needs HoleDistance, and StrokeCount to be identified b4 it..

if (HoleDistance <1  || HoleDistance <0)
		{
				HoleDistance = 0;
				cout <<" Congratulations the Ball is in the Hole!!! " << endl;	
				cout << endl;
                		}


	if (StrokeCount == 5 && HoleDistance <1 )
	
	{
			cout<< "You are on Par Way To Go!!"<<endl;
			cout << endl;
	}
	else 
	
			if (StrokeCount < 5 && HoleDistance <1)
		
			{
				cout <<" You are "<< StrokeCount <<" under Par" << endl;
				cout << endl;
			}
			else
				if (StrokeCount > 5 && HoleDistance <1)
			
				cout <<" You are "<< StrokeCount <<" over Par" << endl;	
				


}

What about now?

#include <iostream>
#include <ctime>
using namespace std;
int main()
{
    char Club =' ';
    char Choice =' ';
    srand(time(0));

    cout << " Would You Like To Play? Press [Y] to Continue [N] to Exit "<<endl;
    cin >> Choice;
    cout << endl;
    cout << endl;
    Choice = toupper(Choice);
    while ( Choice == 'Y')
    { 
        int StrokeCount = 0;
        int StrokeDistance = 0;
        int HoleDistance = 280;

        do
        {
            cout <<"You are " << HoleDistance <<" metres away from the Hole " << endl;
            cout << endl;
            cout << "Select Club [D]river [I]ron [P]utter :  " << endl;
            cin >> Club;
            cout << endl;
            Club = toupper(Club);
            switch (Club)
            {
            case 'D':  
                StrokeDistance = 80 + rand() % (120 - 80 + 1);
                StrokeCount = StrokeCount + 1;
                break;

            case 'I':   
                StrokeDistance = 24 + rand() % (36 - 24 + 1);
                StrokeCount = StrokeCount + 1;
                break;
    
            case 'P':	                  
                StrokeDistance = 8 + rand() % (12 - 8 + 1);
                StrokeCount = StrokeCount + 1;
                break;

            default: 	    
                StrokeCount = StrokeCount + 1;
                cout << " Air Swing 0 Metres Travelled "<<endl;
                cout << endl;
                break;
            }	
            if ( StrokeDistance > HoleDistance )
            {
                StrokeDistance = HoleDistance;
            }
            cout <<"The ball travelled " << StrokeDistance <<" metres "<< endl;
            HoleDistance = HoleDistance - StrokeDistance;
            cout << endl;
        }	
        while ( HoleDistance > 0 );

        HoleDistance = 0;
        cout <<" Congratulations the Ball is in the Hole!!! " << endl;	
        cout << endl;

        cout << " Would You Like To Play? Press [Y] to Continue [N] to Exit "<<endl;
        cin >> Choice;
        cout << endl;
        cout << endl;
        Choice = toupper(Choice);

    }
    system("pause");
    return 0;
}

Just had to make a couple changes and now its perfect thanx!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.