Форум языка CPP

Информация о пользователе

Привет, Гость! Войдите или зарегистрируйтесь.


Вы здесь » Форум языка CPP » Код домашнего задания » Поиск числа в масиве


Поиск числа в масиве

Сообщений 1 страница 2 из 2

1

Код:
srand(time(NULL));//Binding of the generator case to the time

	int    iMassRandomNum[10];    //An array of random numbers
	int    iNumberUsers;    	//The number entered by the user
	int    iPressKey;        //The response to pressing
	bool	bGuessedRight=false;	//Flag check

	
	
	while(1)
	{
    system("cls");
    
    for(int i=0;i<=9;++i) //Filling an array
    {
    	if(i<=9)
    	{
        iMassRandomNum[i]=(rand()%10)+1;
    	}
    }
    

    std::cout<<"Enter a number from 1 to 10"<<std::endl;
    std::cin>>iNumberUsers;
    


    for(int i=0;i<=9;++i)//Check whether the number
    {
    	if(iNumberUsers==iMassRandomNum[i])
    	{
        bGuessedRight=true;
        break; //exit the loop when a match is
    	}
    	else
    	{
        bGuessedRight=false;
    	}
    }



    if(bGuessedRight)//Reaction to check result
    {
    	std::cout<<"Congratulations, you've guessed the number"<<std::endl;
    }
    else
    {
    	std::cout<<"It's a pity you have not guessed the number"<<std::endl;
    }
    	
    std::cout<<"=========================="<<std::endl;

    std::cout<<"Here are all the numbers"<<std::endl;	
    
    
    
    
    for(int i=0;i<=9;++i)//Display an array
    {
    	std::cout<<iMassRandomNum[i]<<' ';
    	
    }
    
    std::cout<<std::endl;
    
    std::cout<<"=========================="<<std::endl;

    std::cout<<"To exit, press \"Esc\", for the continuation of any key"<<std::endl;	
    
    iPressKey = _getch();

    switch(iPressKey)
    {
    	case 224:
        break;
    	case 27:
        return 0;
        break;
    	default:
        ;
    }
	
	}

0

2


Вы здесь » Форум языка CPP » Код домашнего задания » Поиск числа в масиве