I don't understand what is wrong with this.
This is the line with the error: }while(playAgian());
Thank you :)

#include <iostream>
#include <string>

class Ice
{
public:

    void hit(int playerLoco, int iceStrenth, int loco1, int loco2, int loco3);

    int strenth;

    class Loco
    {
    public:
        int location;
        bool hit;

    };
};
void Ice::hit(int playerLoco, int iceStrenth, int loco1, int loco2, int loco3)
{
    if(playerLoco == loco1 || playerLoco == loco2 || playerLoco == loco3)
        iceStrenth = iceStrenth - 1;
}



int main(void)
{
    Ice pie;
    Ice::Loco pie1;
    Ice::Loco pie2;
    Ice::Loco pie3;

    pie.strenth = 3;

    pie1.location = 1;
    pie2.location = 2;
    pie3.location = 3;


    using std::cout;
    using std::cin;
    do
    {
        void play();
        bool playAgian();
    }while(playAgian());
}
void play()
{
    using std::cout;
    cout << "Hi\n";
}
bool playAgian()
{
    using std::cout;
    using std::cin;
    bool playAgian;

    cout << "You scored points. Would you like to play agian? \n"
        << "[1] yes\n"
        << "[2] no\n";
    cin >> playAgian;
    return playAgian;
}

Recommended Answers

All 6 Replies

It would be a lot easier if the code is wrapped in code tags :(

return playAgian;

If the function is a Boolean try to return either true or false

#include <iostream>
#include <string>

class Ice
{
public:

void hit(int playerLoco, int iceStrenth, int loco1, int loco2, int loco3);

int strenth;

class Loco
{
public:
int location;
bool hit;

};
};
void Ice::hit(int playerLoco, int iceStrenth, int loco1, int loco2, int loco3)
{
if(playerLoco == loco1 || playerLoco == loco2 || playerLoco == loco3)
iceStrenth = iceStrenth - 1;
}
bool playAgian()
{
using std::cout;
using std::cin;
bool playAgian;

cout << "You scored points. Would you like to play agian? \n"
<< "[1] yes\n"
<< "[2] no\n";
cin >> playAgian;
return true;
}


int main(void)
{
Ice pie;
Ice::Loco pie1;
Ice::Loco pie2;
Ice::Loco pie3;

pie.strenth = 3;

pie1.location = 1;
pie2.location = 2;
pie3.location = 3;


using std::cout;
using std::cin;

do
{
void play();
bool playAgian();
}
while(playAgian());

}
void play()
{
using std::cout;
cout << "Hi\n";
}

:sad:

  1. You did not bother wrapping the code in [code] tags
  2. did not properly explain your code
  3. Worst of all the code is not even a proper solution

    bool playAgian(){
        using std::cout; 
        using std::cin;
        bool playAgian;
    
        cout << "You scored points. Would you like to play agian? \n"
        << "[1] yes\n"
        << "[2] no\n";
        cin >> playAgian;
        return true;  // :(
    }
    

The function shouldn't always return true... what's the purpose of asking :?:

NO!!! He must define playAgian() function before main()!!!

NO!!! He must define playAgian() function before main()!!!

Why didn't you mention this in your first post, rather you just posted your code without bothering to explain what you did or explain how your code will help?

Yes, Sorry :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.