Hi all,
Im currently working on a c++ program for school, and I thought it would be nice If i framed the output from a function. I looked all over the web to find a solution to no avail. Im completely stuck. I keep getting 2 errors:

*154:35: error: expected '(' for function-style cast or type construction
        <<"|         "<< (*Function)(int c) <<"         |"<<endl*

and

*166:21: error: cannot take the address of an rvalue of type 'void'
                Problem1Container(&LineLoop(6), choice);
                                  ^~~~~~~~~~~~*

Im not really sure how to proceed. How do I go about fixing these errors? Below is a code snippet for all the relevent code, as well as a screenshot of the code im having issue with.

Thank you!

P.S if there is any other information I should add, let me know. im fairly new to online forums.

void LineLoop(int size)
{
    int x;
    string line;
    for(x = 0; x <= size; x++)
        {
            line = line + "-";
        }
        cout << line <<endl;
}
void Problem1Container(void (*Function) (int c) ,int choice)
{
    cout
    <<"*-----------Output------------*"<<endl
    <<"|                             |"<<endl
    <<"|         "<< (*Function)(int c) <<"         |"<<endl
    <<"|                             |"<<endl
    <<"*-----------Output------------*"<<endl;
}


void Problem1Pics(int choice)
{

    string line;
    if(choice == 1) //lines
    {
        Problem1Container(&LineLoop(6), choice);
    }

screenshot: http://prntscr.com/8rs5dm

Show all of the relevant code, including headers (class definitions and function declarations), as well as implementation code for the classes/functions that are failing. You are not providing enough information. We especially need the entire section of code where the errors are occuring and you are only providing segments.

Comments
I'm sorry, Ill update it

@alek - no problem! I'll look at it after it is posted. At earliest it will be this time tomorrow. I don't get home from work until late.

Here is the full code(keep in mind I have not finished the program yet, im only done with the first problem):

#include <iostream> 
#include <cstdlib>
#include <ctime>
#include <stdlib.h>

using namespace std;

void header()
{
    cout
    <<"********************************************"<<endl
    <<"||  RPS and Dice Game - Alek M----------- ||"<<endl
    <<"********************************************"<<endl;
}

int gamechoice() //chooses what game
{
    cout <<endl
        << "*******************************"<<endl 
        << "* 1. Play Rock/Paper/Scissors *" <<endl
        << "* 2. Play Dice Role Game      *" <<endl
        << "* 3.Exit(If any other input)  *" <<endl
        << "*******************************"<<endl 
        <<"Enter your choice: ";

        return 0;
}


//RPS Game





int RPSProcess(int player, int CPU) //logic for the Rock Paper Scissors
{
    if(player == CPU)
        cout << "You have a tie!" <<endl;
    else if (player == 1 && CPU == 2)
        cout << "You lose!"<< endl;
    else if (player == 2 && CPU == 3)
        cout << "You lose!"<< endl;
    else if (player == 3 && CPU  == 1)
        cout << "You lose!" << endl;
    else
        cout << "You win!" <<endl;

    return 0;



}



void RPSInstructions() //prints instructions for Rock Paper Scissors
{

    cout << endl <<endl
        <<"*****************************" <<endl 
        << "* Rock/Paper/Scissors Game  *"<< endl
        << "* The rules are:            *" <<endl
        << "*\tRock beats scissors *" <<endl
        << "*\tScissors beat paper *" <<endl
        << "*\tPaper beats rock    *" <<endl
        <<"*****************************" <<endl<<endl; 

    cout <<"Game Choices"<<endl
        << "1. Rock"<<endl
        << "2. Paper" <<endl
        <<"3.Scissors"<<endl
        <<"Enter your choice: ";
}


int RPSGenerator() //generates random number 1-3
{
    return (rand()%3)+1;
}


int RPSGame() //Runs the Rock Paper Scissors game
{
    int choice;
    RPSInstructions(); //displays instructions
    cin >> choice;
    choice = tolower(choice);
    int CPU = RPSGenerator(); //sets CPU choice to random generated number
    RPSProcess(choice, CPU); //processes what the result is
return 0;

}




//dice game




void DiceInstructions() //instructions for the dice game
{
    cout << endl 
        << "******************************************************************"<<endl 
        << "* Role Dice Game                                                 *"<< endl
        << "* The rules are                                                  *" << endl
        << "*\tYou get 10 points if you get two dice and get a 7.       *" <<endl
        << "*\tYou get 5 if you role two dice and get identical numbers.*" <<endl
        << "*\tYou get 3 points if you role one dice and get 4.         *" <<endl
        << "******************************************************************"<<endl<<endl;

    cout << "Game Choices:" <<endl
        << "\t1. Roll only one dice" <<endl
        << "\t2. Roll two dice" <<endl
        << "\t3.Quit, Exit your program"<<endl<<endl
        <<"Please Enter your choice: ";
}


void DiceLogic(int D1, int D2) //dice logic
{
    int score; //score for the game 

    if(D2 == 0) //if theres only 1 die, then Die 2 will be 0 by default
        cout << "You rolled a " << D1 <<endl;
    else
        cout << "You rolled a " << D1 << " and a " << D2 <<endl; //else there are two die. 

    if(D1 + D2 == 7)
        score  = 10;
    else if(D1 ==  D2)
        score = 5;
    else if(D2 == 0 && D1 == 4)
        score = 3;
    else
        score = 0;

    cout << "You Scored a "<< score << "!" << endl;


}


int DiceGenerator() // generates random number for dice. 
{
    return (rand()%6)+1;
}

int DiceGame() //runs the dice game.
{
    int choice;
    int dieA, dieB;

    DiceInstructions();
    cin >> choice;

    dieA = DiceGenerator();
    dieB = DiceGenerator();

    if(choice == 1)
        DiceLogic(dieA, 0);
    else if (choice == 2)
        DiceLogic(dieA,dieB);
    else
    {
        cout << "Goodbye!" <<endl;
        exit(0);
    }

    return choice;
}





int programstart() //allows you to choose between games and if you want to play again. 
{
    int choice;
    gamechoice();
    cin >> choice;

    if(choice == 1)
        RPSGame();
    else if(choice == 2)
        DiceGame();
    else
    {
        cout << endl << endl << "Goodbye!" << endl;
        exit(0);
    }

    char playagain;
    cout << "Play again?(y/n): ";
    cin >> playagain;
    playagain = tolower(playagain);

    if(playagain =='y')
        programstart();
    else
        cout <<"Goodbye!";

    return 0;
}




int main() //main function calls the program to start, as well as initilaizes the random generator. 
{
    srand(time(NULL));
    header();
    programstart();

    return 0;
}
This article has been dead for over six months. Start a new discussion instead.