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 4569234
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:11:22+00:00 2026-05-21T19:11:22+00:00

I have this program I’ve been working on for a while, which is basically

  • 0

I have this program I’ve been working on for a while, which is basically a checkers game where somebody can either decide to play against a player or watch a computer simulation. Now both of these are basically the same code, except for the fact that the computer simulation takes randomized values. Both of these code blocks are located in my driver and I want to break up the code into two different cpp files. This way I have user input decide what is going to happen.

so for example:

if(x == 1)
  call the player cpp file

else if (x == 2)
  call the simulation cpp   

My program is object-oriented, but I was wondering if there is a way to just run code from a different file without creating a class and defining functions?

  • 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-05-21T19:11:23+00:00Added an answer on May 21, 2026 at 7:11 pm

    You could do something like

    if (x == 1)
    {
        #include "player.cpp"
    }
    else if (x == 2)
    {
        #include "simulation.cpp"
    }
    

    And have the individual .cpp files contain the logic for each major section. This is a bit clunkier though that just wrapping the functionality in some functions and call those from your if-if-else statements. At least with functions if something goes wrong, it will be easier to debug or do stack-traces, etc. rather than chase around multiple .cpp files.

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

Sidebar

Related Questions

Consider this problem: I have a program which should fetch (let's say) 100 records
Ok, so I have this program with many (~300) threads, each of which communicates
I have this program in c++: #include <iostream> using namespace std; int main() {
Okay, I have this program and I don't want more than one instance of
I have an executable that is started by a windows service, this program will
Well, I have this bit of code that is slowing down the program hugely
Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
Suppose that I have a Java program within an IDE (Eclipse in this case).
I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to
I have some code that effectively does this : File file = new File(C:\\Program

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.