C++ 我的程序不是';我不能使用我代码的某些部分

C++ 我的程序不是';我不能使用我代码的某些部分,c++,C++,我需要我的程序的帮助,当用户输入一个不是彩票中奖者的号码时,它仍然会说中奖者。如果你能给我更好的关于线性搜索功能的建议,那会很神奇,下面是我的代码: #include <iostream> #include <cstdlib> using namespace std; bool input(double); const int LUCKY_NUMS =10; // Function prototype that searches winning ticket num

我需要我的程序的帮助,当用户输入一个不是彩票中奖者的号码时,它仍然会说中奖者。如果你能给我更好的关于线性搜索功能的建议,那会很神奇,下面是我的代码:

#include <iostream>
#include <cstdlib>
using namespace std;

bool input(double);

const int LUCKY_NUMS =10;

// Function prototype that searches winning ticket number
bool ticketSearch(const int [], int, int);

int main ()
{
    //user continues playing lotto

    char again;

    const char QUIT = 'N';
    //determines if player's ticket is a winner

    int winningNum;
    //5 digit ticket number entered by player

    int playerNum;
    //holds winning ticket number

    int ticket;

    //Array holding the winning tickets for each week

    int lottoTix[LUCKY_NUMS] = {13579, 26791, 26792, 33445, 55555,
                                62483, 77777, 79422, 85647, 93121};

    //Player decides if they want to continue playing

            for (int week = 0; week < 10; week++)
            {
            //Winning lotto ticket for each week (10 weeks total)

                ticket = lottoTix[week];
                do
               {
                    cout << "Please enter your 5-digit ticket number for     week " << (week + 1) << ": " << endl;

            //Player's ticket number

            cin >> playerNum;
            }while(input(playerNum));



            //Calls linear search for winning lotto ticket

            winningNum = ticketSearch(lottoTix, LUCKY_NUMS, playerNum);

            //Error message if player's number is not the winning ticket
            //here is where my problems occurs it doesn't use this part of code at all
            if (playerNum != lottoTix[LUCKY_NUMS])
            {

                cout << "Sorry, you did not win the MEGAMILLIONS lottery. ";
                cout << "Thanks for playing! ";
                cout << "Play again? (Y/N)";
                    cin >> again;
            }

            //Player wins the lottery
            else if (playerNum == lottoTix[LUCKY_NUMS])
            {

                cout << "You have just won 598 MILLION DOLLARS!!! ";
                cout << "CONGRATULATIONS!!!";
                cout << "Play again? (Y/N)";
                cin >> again;
            }


            if ((again != 'Y') && (again != 'y'))
                {
                    //exit message
                    cout << "Press [Enter] to exit...\n\n";
                    //exits program
                    exit(0);
                }
        }
   return 0;
}

//linear search for winning ticket of the week
bool ticketSearch(const int ticketList[], int numTickets, int winningNum)
{
int index = 0;
int position = -1;
bool found = false;

while ((index < numTickets) && !found)
{
    if (ticketList[index] == winningNum)
    {
        found = true;
        position = index;
    }
    index ++;
    }
    return found;
}
// function does invalid input
bool input(double number)
{
if (number < 0 || number >=99999 ||  cin.fail())
{
    cin.clear();
    cin.ignore();
    cout <<"\nYou have entered an invalid answer\n" << endl;
    return true;
}
 else
     return false;
#包括
#包括
使用名称空间std;
布尔输入(双);
const int LUCKY_NUMS=10;
//搜索中奖票号的功能原型
bool ticketSearch(const int[],int,int);
int main()
{
//用户继续玩乐透
再次烧焦;
const char QUIT='N';
//确定玩家的票是否为赢家
int winningNum;
//玩家输入的5位数票号
int playerNum;
//持有中奖票号
国际机票;
//持有每周中奖彩票的阵列
int lottoTix[LUCKY_NUMS]={1357926791,26792,33445555,
62483, 77777, 79422, 85647, 93121};
//球员决定是否继续比赛
对于(整数周=0;周<10;周++)
{
//每周中奖彩票(共10周)
票=乐透券[周];
做
{

cout代码的问题是,从函数返回的值应该是布尔值。winningNum是一个整数。此外,您可以使用诸如“如果找到元素”之类的内容,然后做一些事情。您也可以使用for循环进行线性搜索。

请您的问题提供一个。解决此类问题的正确工具是调试器。在询问堆栈溢出问题之前,您应该逐行检查代码。有关更多帮助,请阅读。至少,您应该[编辑]您的问题包括一个重现您的问题的示例,以及您在调试器中所做的观察。您为什么将playerNum与lottoTix[LUCKY_NUMS]进行比较?(LUCKY_NUMS是常量整数)