Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9253373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:12:11+00:00 2026-06-18T11:12:11+00:00

I have been trying to pass a struct, which hold all my vars, to

  • 0

I have been trying to pass a struct, which hold all my vars, to multiple functions, which are saved in a separate class. I know the error has to do with some sort of syntax error, most likely, but I do not see what I have done wrong.

The main.ccp is:

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include "running.h"

using namespace std;

int main()
{
    //------Class Objects---------
    running runObj;

    //----------Vars--------------

    char saveGame = 'N';
    struct gameVar
    {
        int correctGuesses;  // These vars need to be reset for each new game.
        int Lives;
        int rowCorrect;
        int highScore;
        char anotherGame;
    } values;
    values.highScore = 12;
    values.anotherGame = 'Y';

    //--------Game Loop-----------

    // int highScore2 = runObj.readHighScore();


    while (values.anotherGame = 'Y')
    {
        struct gameVar = runObj.processGame(gameVar);
        struct gameVar = runObj.afterText(gameVar);
        gameVar values;
        values.anotherGame;
    }


    cout << endl << "-------------------------------------------------------" << endl;
    cout << "Would you like to save your high score? Y/N" << endl;
    cin >> saveGame;

    if(saveGame == 'Y')
    {
        runObj.saveHighScore(gameVar);
    }

    return 0;
}

My header file is:

#ifndef RUNNING_H
#define RUNNING_H


class running
{
    public:
        struct gameVar processGame(struct gameVar);
        void saveHighScore(struct hs);
        int readHighScore();
        struct gameVar afterText(struct gameVar);
};

#endif // RUNNING_H
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:12:13+00:00Added an answer on June 18, 2026 at 11:12 am

    First of all, a simple issue: you are using = in your while loop condition, which will assign the value 'Y' to gameVar.anotherGame. What you actually want is ==, to test for equality.

    Take a look at this line:

    struct gameVar = runObj.processGame(gameVar);
    

    What are you trying to do here? gameVar is the name of your struct, not an object of gameVar type. Your object is actually called values. Perhaps you were wanting to do something like:

    values = runObj.processGame(values);
    

    Ditto for the next line too.

    It seems like the reason you have this confusion is because you’re defining your struct at the same time as creating an object of that type. The struct called gameVar is just a blueprint for objects and you create an object that matches that blueprint called values:

    struct gameVar
    {
      // ...
    } values;
    

    You might be less confused if you define the struct outside the main function as:

    struct gameVar
    {
      // ...
    };
    

    And then create the instance of it in main with:

    gameVar values;
    

    It is this values object that you must pass to a function – you can’t pass a type, which is what gameVar is.

    I’m not sure what you were then attempting to do with:

    gameVar values;
    values.anotherGame;
    

    This would redefine the values object within the while loop and it will be destroyed at the end of the loop. You then access the data member anotherGame but don’t do anything with it. Maybe you’re looking for:

    gameVar values;
    values.highScore = 12;
    values.anotherGame = 'Y';
    
    while (values.anotherGame == 'Y')
    {
        values = runObj.processGame(values);
        values = runObj.afterText(values);
    }
    

    It’s worth noting that in C++, you do not need to put struct before every use of the gameVar type. The type name is just gameVar. That is, you could change your declaration of processGame to: gameVar processGame(gameVar);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to pass a pyplot Figure out of an external class
i have been trying to pass some variables to model through the controller function
I have been trying to pass a string value from one method into another.
I have been trying to create a ListView which I can sort using drag
I have been trying for hours to pass a resource from one Activity to
(I am a newbie on Objective-C, and) I have been trying to pass a
I have been trying to figure out how all this validation works, but I
I have been trying to make a stored procedure which autodeletes temporary tables. CREATE
I have been trying to pass and modify data from the client side of
So lately I have been trying ways to pass data from a child to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.