-
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?
-
1) See the FAQ about running another program from inside your program.
2) Use a loop.
-
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;
Code:
#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
switch(number){
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;
}
while(!_kbhit());
}
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.