the program is running well but concept is wrong.
you should find number 0-100 until 10 trials.
if failed, and want to play again unfortunately program is terminated why ?

#include <cstdlib>
#include <iostream>
#include <windows.h>
using namespace std;

int sayiturev (int aralik) // generating number 1-100
{
srand(GetTickCount());
int sayi=rand()%aralik;
return sayi;
}

int tekrar ()   // replay decision 
{
    int karar;
    cout << "do you want to play ? yes-1 no-0"<<endl;
    cin>>karar;
    return karar;
}
int main(int argc, char *argv[])
{
    int sayi1;
    int sayi2,sor,karar2,son;
    int xxx=9;
    system("color 3a");
    sayi1=sayiturev(100);
    sor:
        if (xxx==0) goto son;
        else
        {
        do
        {
                         
    cout << "enter numner=";
    cin >> sayi2; // number input for guess
       if (sayi2==sayi1) 
        {
        cout << "congratulation....it is correct "<<10-xxx<<".counter\n"<<endl;
        xxx=10;
        karar2=tekrar();           
        sayi1=sayiturev(100); // number generator. 
        }
        else if (sayi2<sayi1) 
        {
        cout << "enter more than this \n \n";
        xxx--;
        goto sor;
        }
         else if (sayi2>sayi1) 
        {
        cout << "enter less than this \n  \n";
        xxx--;
       goto sor;
        } 
       } while(karar2==1); 
          system("PAUSE");
    return EXIT_SUCCESS;   
       }
       son:
           {
                          cout << "you did not find \n \n";
                          cout << "number was=" << sayi1;
                          karar2=tekrar ();
                          }
  
}

When the user enters the number wrong 10 times, xxx becomes equal to 0.

And then this code

if (xxx==0) goto son;

causes it to exit. Modify the tekrar function, so that it resets xxx. It asks the user if he would like to play more but doesn't changes xxx variable which causes termination. Or you can manually reset xxx everytime tekrar is called.

Edited 6 Years Ago by vidit_X: n/a

What is your Question?

If you want the program to start again then you need a while loop with a terminating character.

#include <iostream>
#include <string>

using namespace std;
  
int main()
{
    int Guess_Val = 0,Rand_Val = 0, Counter = 10;
    bool Condition=false;

	Rand_Val = rand() % 100 + 1;
    
    //Loop starts here
    while(Condition != true && Counter != 0)
	{
	cout<<"Enter Your Guess Value:"<<endl;
    cin>>Guess_Val;
    Counter--;
	
	if(Guess_Val == Rand_Val)
	{
	   Condition = true;
	}

	else if(Guess_Val>Rand_Val) 
	{
	   cout<<"Guess Value is High"<<endl; 
	}

	else if(Guess_Val<Rand_Val) 
	{
	   cout<<"Guess value is Low"<<endl;

	}


	}

	if(Condition == true)
	{
	   cout<<"Congratulation Your Guess was Right"<<endl;
	}

	else if(Counter == 0) 
	{
		cout<<"You Couldn't guess the value, The number was : "<<Rand_Val<<endl;

	}

	//Loop ends here   
    return (0);
}

Edited 6 Years Ago by Software guy: n/a

This question has already been answered. Start a new discussion instead.