用bool函数确定末端
Determing the End with a Bool function
我正在尝试创建一个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;
}
}
相关文章:
- 使用 bool 和 const char 重载的 C++ 函数会在没有警告的情况下产生歧义 (MSVC2012)
- 合并 2 个排序的链表。必需的成员函数 bool Merge(List342 &list1):
- C bool表达式作为函数参数调用错误的超载
- 将 std::vector<bool> 传递给外部函数
- 尝试创建一个评估字符的bool函数,如果字母数字为字母,则返回true
- 引用 std::atomic <bool>的已删除函数错误
- bool值不在腔函数函数中重新调整false,c
- 在矩阵C 中使用Bool函数检查重复数字
- 当Bool值在UPDATE()方法中更改时,只有一次呼叫函数
- 我的bool函数一直返回true,我不知道为什么
- 返回 std::p air<const CustomClass &, bool> 用于搜索函数中的失败情况,当 CustomClass 是抽象基类时
- C++变体用bool转换构造函数
- 使用 Bool 函数在 C++ 中进行递归二叉搜索
- 用bool函数确定末端
- 如何让bool函数主要做一些事情
- 控制到达bool函数中非void函数的结束
- 由于c++ bool函数的StackOverflowException导致进程终止
- Bool函数总是返回false
- 在if参数中调用bool函数
- c++回文Bool函数(使用指针)