Still not working. It compiles and executes, but it does very weird things...
Please help.
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <fstream.h>
void get(char prompt[100], char input[100]) //get(prompt, variable);
{//get - prompts and gets a value
cout << "Enter " << prompt << ": ";
gets(input);
}//end of get function
void get(char prompt[100], int input) //get(prompt, variable);
{//get - prompts anbd gets a value
cout << "Enter " << prompt << ": ";
cin >> input;
}//end of get function
//function prototypes
void addInitialize(char[100]);
void addInput(char[100], char[100]);
void addProcessing(char[100], char[100][100], int &);
void addOutput(char[100], char[100][100], int);
void main()
{//main - main function
//declare fstream commands
ofstream fout;
ifstream fin;
//intro
cout << "Program Writer\n\n";
getch();
//declare main function variables
char filename[100] = ""; //name of file
char x = 'n'; //multi-use variable (character)
int y; //multi-use variable (integer)
char initialize[100][100] = {""}; //initialization commands
char input[100][100] = {""}; //input commands
char processing[100][100] = {""}; //processsing commands
char output[100][100] = {""}; //output commands
int length[4] = {0,0,0,0}; //numbers of commands {initialize, input, processing, output}
while (x != 'y' && x != 'Y')
{//create file
//gets(filename);//debug
get("Filename (not including extension)",filename);
strcat(filename, ".cpp"

;
fin.open(filename);
if (fin.is_open() )
{//if file already exists
cout << "Erase existing file? (y/n)";
cin >> x;
}//end if file already exists
else
{
cout << "Huh";
x = 'y';//if file DOES NOT exist
}
}//end create file
fin.close();
//write beginning of file
fout.open(filename);
fout << "//Created using Program Writer\n"
<< "#include <iostream>\n"
<< "#include <string.h>\n"
<< "using namespace std;\n"
<< "void main()\n"
<< "{\n\t";
main:
//main menu
system("cls"

;
cout << "***MAIN MENU***\n"
<< "(1)Add Input\n"
<< "(2)Add Calculation\n"
<< "(3)Add Output\n"
<< "(4)Done\n\n";
get("selection",y);
switch

{//add commands branch
case 1:
//add input
addInitialize(initialize[length[0]]);
addInput(input[length[1]], initialize[length[0]]);
length[0]++;
length[1]++;
cout << "Input added";
getch();
goto main;
case 2:
//add calculation (processing)
addProcessing(processing[length[2]], initialize, length[0]);
length[2]++;
cout << "Calculation added";
getch();
goto main;
case 3:
//add output
addOutput(output[length[3]], initialize, length[0]);
cout << "Output added";
goto main;
}//end add commands branch
//write commands to file
for (y = 0; y < length[0]; y++)//write initializations
fout << "\t" << initialize[y] << endl;
for (y = 0; y < length[1]; y++)//write input
fout << "\t" << input[y] << endl;
for (y = 0; y < length[2]; y++)//write processing
fout << "\t" << processing[y] << endl;
for (y = 0; y < length[3]; y++)//write output
fout << "\t" << output[y] << endl;
//write end of file
fout << "}";
cout << "\nProgram completed and ready for compliling...\n";
}//end of main function
void addInitialize(char initialize[100]) //addInitialize(initialize command);
{//addInitialize - add initialization command
//declare addInitialize variables
int x = 0; //multi-use variable (integer)
char y[100] = ""; //multi-use variable (string)
//select variable type
cout << "\nVARIABLE TYPES\n"
<< "(1)Integer\n"
<< "(2)Real Number\n"
<< "(3)Character\n"
<< "(4)String\n\n";
while (x < 1 || x > 4)
get ("selection", x);
switch(x)
{//select variable type branch
case 1:
//integer
strcpy(y, "int "

;
break;
case 2:
//real number
strcpy(y, "float "

;
break;
case 3:
//character
strcpy(y, "char "

;
break;
case 4:
//string
strcpy(y, "char* "

;
}//end select variable type branch
initialize = y;//add variable type to command
gets

;//debug
//get name of variable
get("name of variable", y);
strcat(initialize, y);//add variable name to command
//get initial value
get ("initial value", y);
//add initial value to command
if (x == 1 || x == 2)
{
strcat(initialize, " = "

;
strcat(initialize, y);
}
else if (x == 3)
{
strcat(initialize, " = "

;
strcat(initialize, "'"

;
strcat(initialize, y);
strcat(initialize, "'"

;
}
else
{
strcat(initialize, " = "

;
strcat(initialize, "\""

;
strcat(initialize, y);
strcat(initialize, "\""

;
}
strcat(initialize, ";"

;//end command line
}//end of addInitialize function
void addInput(char input[100], char variable[100]) //addInput(input command, variable);
{//addInput - add input command
//declare addInput variables
char x[100] = ""; //multi-use variable (string)
int y = 0; //multi-use variable (integer)
while (strchr(variable+y,'=') != 0)
y++;
strncpy(variable, variable+7, y-7);
//get variable prompt
get("Variable Prompt", x);
//create input command
strcpy(input, "cout << \"Enter "

;
strcat(input, x);
strcat(input, ": \";\n\t"

;
if (strcmp(variable, "char*"

== 0)
{
strcat(input,"gets("

;
strcat(input, variable);
strcat(input, "

;"

;
}
else
{
strcat(input, "cin >> "

;
strcat(input, variable);
strcat(input, ";"

;
}
}//end of addInput function
void addProcessing(char processing[100], char variables[100][100], int &len) //addProcessing(processing command, variable list, length of variable list);
{//addProcessing - add processing command (calculation)
//display list of variables
cout << "AVAILABLE VARIABLES\n";
for (int i = 0; i < len; i++)
cout << "(" << i+1 << "

" << variables
<< endl;
cout << "(" << len+1 << "
New Variable\n";
//select final variable
int x = 0; //multi-use variable (integer)
while (x < 1 || x > len+1)
get("Final Variable", x);
if (x == len+1)
{//create new variable
addInitialize(variables[len]);
len++;
}//end create new variable
x--;
int y = 0; //multi-use variable (integer)
while (strchr(variables[x]+y,'=') != 0)
y++;
//write beginning of processing command
strncpy(processing,variables[x]+7, y-7);
strcat(processing, " = "
;
//get final variable
char formula[100] = ""; //formula to get final variable
cout << "Ex. (variable1 + variable2) * variable 3\n";
gets(formula);//debug
get("formula to get final (include names of variables)",formula);
//make end of processing command
strcat(processing, formula);
strcat(processing, ";\n"
;
}//end of addProcessing function
void addOutput(char output[100], char variables[100][100], int length)//addOutput(output command, variable list, length of variable list);
{//addOutput - add output command
//display list of variables
cout << "AVAILABLE VARIABLES\n";
for (int i = 0; i < length; i++)
cout << "(" << i+1 << "
" << variables << endl;
cout << "(" << length+1 << "
No Variable\n";
//select variable
int x = 0; //multi-use variable (integer)
while (x < 1 || x > length+1)
get("Output Variable", x);
x--;
//get comment
char y[100] = ""; //multi-use variable (string)
gets
;//debug
int z = 0; //multi-use variable (integer)
while (strchr(variables[x]+z,'=') != 0)
z++;
get("Comment",y);
char a[100] = ""; //multi-use variable (string)
//write output command
strncpy(a,variables[x]+7, z-7);
if (x != length+1)
{
strcpy(output, "cout << \""
;
strcat(output, y);
strcat(output, ":\" << "
;
strcat(output, a);
strcat(output, "<< endl;"
;
}
else
{
strcpy(output,"cout << \""
;
strcat(output, y);
strcat(output, "\n\";"
;
}
}//end of addOutput command