Thread: 2 Basic Questions

  1. #1
    Registered User
    Join Date
    Apr 2007

    2 Basic Questions

    I'm sorry if I sound stupid with these questions.

    My first is I want to know if it is possible to get one file to open another. An example, if I have a main.cpp file, and when the user enters the number 1, I want it to run a small math program which has been programmed and compiled to the filename math.exe. I've been trying to figure it out but can't find how to do it. Can someone help?

    Also, when a program finishes, how would I go about getting it to re-start instead of quitting?

  2. #2
    Registered User
    Join Date
    Jan 2005
    1) See the FAQ about running another program from inside your program.
    2) Use a loop.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Why would you want to make two seperate programs when you can include the math program within the main.exe? Use a switch case to determine what "program" you want to run, such as;

    #include <cmath>
    #include <conio.h>
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    int main(){
         int number;
         double a, b, c, again;
         again = 1;
         while(again == 1){
            cout<<"enter 1 for math, 2 for misc, 3 for whatever" << endl;
            cin>> number;
            //this is where it decides what case to go to
                case 1:
                    a = b + c; //whatever a, b, and c might be
                    cout<< a << endl;
                case 2:;
                    //put second math function here
                case 3:;
                    //third math thingy
            //loops it around, this is just a simple loop/restart 
            cout<<"Try again? (1 for yes, 0 for no)" << endl;
            cin>> again;

    this ends up printing some bogus numbers cause I did not tell it what a, b, and c were, but you get the idea. To keep a program open, loop it around. while, for, and do-while loops will all do the job.
    Last edited by scwizzo; 04-05-2007 at 06:17 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic Questions
    By Panda_ in forum C Programming
    Replies: 15
    Last Post: 09-23-2009, 04:24 PM
  2. many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  3. Some Basic questions
    By BlaX in forum C Programming
    Replies: 7
    Last Post: 06-30-2009, 09:51 AM
  4. Please help, basic unsigned conversion questions
    By ninjacookies in forum C Programming
    Replies: 3
    Last Post: 04-20-2005, 10:50 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM