Reputation: 35
I am trying to create a Play() function (think like a media player type play) that checks first to make sure that the given object isn’t at the end of its selections (if it is, the user will be told to rewind.)
I have a bool function called IsCAtEnd(). It’s supposed to find out if C is at the end. Right now I have something like this in it:
bool AC::IsCAtEnd()
{
CAtEnd = (CurrentSelect == NumOfSelect)
if (CAtEnd)
{return true;}
else
{return false;}
}
And in my Play() function I have something like this –
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;
}
It compiles and runs but not as I’d like it too. For one, if I enter the last selection (Say C has 6 selections and I want to play the last one) it will tell me to rewind. Instead, I want it to play that selection and the next time Play is called tell me to rewind (recalling that the last time Play was called, it was on the last selection). I also want it to continue to prompt the user to rewind until they do so (so no calling play again, choosing a different selection and having that selection play).
I know I need to make it so that if the last selection is put in, the CAtEnd variable is changed to true after it is played. That way the next time around it’ll state that it needs to be rewound. I’m not sure how to do it though.
Upvotes: 1
Views: 104
Reputation: 46
If you want the program to continuous run and with user input when prompting rewind msg, you can have a while 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;
}
}
Upvotes: 0
Reputation: 46
I think you want to play it first for any choice. Then check whether it is the last one or not. if it is last one, you prompted the rewind message, otherwise, do nothing.
you can change it like this
if(currentSelection <= NumberOfSelection)
{
cout << “Playing “ << CurrentSelection << endl;
}
If (IsCAtEnd())
{
cout << “You need to rewind first.” << endl;
}
Upvotes: 2