用bool函数确定末端

Determing the End with a Bool function

本文关键字:bool 函数      更新时间:2023-10-16

我正在尝试创建一个play(像媒体播放器类型播放),该功能首先检查以确保给定对象不在其选择末尾(如果是这样,将告诉用户倒带。)

i具有称为iscatend()的bool函数。应该找出C是否在最后。现在我有类似的东西:

bool AC::IsCAtEnd()
{
CAtEnd = (CurrentSelect == NumOfSelect)
if (CAtEnd)
{return true;}
else
{return false;}
}

和在我的play()函数中,我有类似的东西 -

void AC::Play()
{
int Choice;
cout << Enter Selection to Play: “;
cin >> Choice;
CurrentSelection = Choice;
If (IsCAtEnd())
{
cout << “You need to rewind first.” << endl;
}
else
{
cout << “Playing “ << CurrentSelection << endl;
}

它编译并运行,但也不是我想要的。首先,如果我输入最后一个选择(例如C有6个选择,我想扮演最后一个),它将告诉我倒带。取而代之的是,我希望它可以玩那个选择,下次播放被称为告诉我要倒带(回想一下最后一次播放是在最后的选择中)。我还希望它继续提示用户倒带直到这样做(所以再也没有打电话播放,选择其他选择并进行选择游戏)。

我知道我需要做到这一点,以便如果将最后一个选择放入,则在播放后,Catend变量将更改为True。这样,下次周围的方式就会指出它需要陷入困境。我不确定该怎么做。

我想您想首先播放它。然后检查它是否是最后一个。如果是最后一个,则提示倒带消息,否则,什么都不做。

您可以像这样更改它

if(currentSelection <= NumberOfSelection)
{
     cout << “Playing “ << CurrentSelection << endl;
}
If (IsCAtEnd())
{
     cout << “You need to rewind first.” << endl;
}

如果您希望程序连续运行并在提示Rewind MSG时使用用户输入,则可以有一个wirer loop

    int Choice;    
    cout << Enter Selection to Play: “;
    cin >> Choice;
    while(choice != 0)
    {
         CurrentSelection = Choice;
         if(currentSelection <= NumberofSelection)
             cout << “Playing “ << CurrentSelection << endl;
        if (IsCAtEnd())
        {
            cout << “You need to rewind first.” << endl;
            cout << Enter Selection to Play: “;
            cin >> Choice;
        }
}