PDA

View Full Version : Using two .cpp files



RickyRombo
04-02-2009, 10:52 PM
[SOLVED]
I created a color selector for the user to choose what color the text and background are in colortext.cpp and the mad lib in Main.cpp:

colortext.cpp:


#include <conio.h>
#include <iostream>
#include <stdlib.h>
#include<dos.h>
#include <string>
using namespace std;

int start;

int main();

int colortext(start)
{

unsigned int key;
int colorcode;

cout<<"Mad lib: RickyRombo"<<endl<<"<<<<<<<<<<<<<>>>>>>>>>>>>>"<<endl<<"Press \"/\" for color options or press any other key to continue."<<endl;
key = getch();
if(key = '/'){
do{
cin>>colorcode;

switch(colorcode)
{
case 01:
system("color 01");
break;
case 02:
system("color 02");
break;
case 03:
system("color 03");
break;
case 04:
system("color 04");
break;
case 05:
system("color 05");
break;
case 06:
system("color 06");
break;
case 07:
system("color 07");
break;
case 8:
system("color 08");
break;
case 9:
system("color 09");
break;
case 10:
system("color 10");
break;
case 12:
system("color 12");
break;
case 13:
system("color 13");
break;
case 14:
system("color 14");
break;
case 15:
system("color 15");
break;
case 16:
system("color 16");
break;
case 17:
system("color 17");
break;
case 18:
system("color 18");
break;
case 19:
system("color 19");
break;
//YadahYadah...

case 43:
system("color 43");
break;

case 45:
system("color 45");
break;
case 46:
system("color 46");
break;
case 47:
system("color 47");
break;
case 48:
system("color 48");
break;
case 49:
system("color 49");
break;
case 50:
system("color 50");
break;
case 51:
system("color 51");
break;
case 52:
system("color 52");
break;
case 53:
system("color 53");
break;
case 54:
system("color 54");
break;
case 56:
system("color 56");
break;
case 57:
system("color 57");
break;
case 58:
system("color 58");
break;
case 59:
system("color 59");
break;
case 60:
system("color 60");
break;
case 62:
system("color 62");
break;
case 61:
system("color 61");
break;
case 63:
system("color 63");
break;
case 64:
system("color 64");
break;
case 65:
system("color 65");
break;
case 67:
system("color 67");
break;
case 68:
system("color 68");
break;
case 69:
system("color 69");
break;
case 70:
system("color 70");
break;
case 71:
system("color 71");
break;
case 72:
system("color 72");
break;
case 73:
system("color 73");
break;
case 74:
system("color 74");
break;
case 75:
system("color 75");
break;
case 76:
system("color 76");
break;
case 78:
system("color 78");
break;
case 79:
system("color 79");
break;
case 80:
system("color 80");
break;
case 81:
system("color 81");
break;
case 82:
system("color 82");
break;
case 83:
system("color 83");
break;
case 84:
system("color 84");
break;
case 85:
system("color 85");
break;
case 86:
system("color 86");
break;
case 87:
system("color 87");
break;
case 89:
system("color 89");
break;
case 90:
system("color 90");
break;
case 91:
system("color 91");
break;
case 92:
system("color 92");
break;
case 94:
system("color 94");
break;
case 95:
system("color 95");
break;
case 96:
system("color 96");
break;
case 97:
system("color 97");
break;
case 98:
system("color 98");
break;
case 93:
system("color 93");
break;
default:
cout<<"This color does not exist."<<endl;
cout<<"Press q to quit or anything else to keep looking"<<endl;
key = getch();
if(key ='q')
{
break;
}
}


}
while (key !='q');
}

return (start+1);
}



Main.cpp:


#include <iostream>
#include <stdlib.h> // for system ("cls")
#include <conio.h> // for getch()
#include <string>
#include<dos.h>

extern int start;

int colortext(int start);

using namespace std;

int main()
{
string adjective1;
string adjective2;
string adjective3;
string adjective4;
string verbal1;
string verbal2;
string animal1;
string animal2;
string name1;
string name2;
string name3;
string name4;
string food1;
string sound1;
string fight1;
string hole1;
string place1;
string object1;
string transport1;
string transport2;
string place2;
string place3;
string place4;
string newspaper1;
string object2;
string relative1;
string adjective5;
string adjective6;
string name5;
string race1;
string bodypart1;
string no1;
string color;
int dummy;



if(start != 1)
{

colortext(dummy);
}
cin.ignore(1049);
cout<<"Give me some adjectives:"<<endl;
getline(cin, adjective1);
getline(cin, adjective2);
getline(cin, adjective3);
getline(cin, adjective5);
getline(cin, adjective6);
cout<<"This one has to be capitalized:"<<endl;
getline(cin, adjective4);
cout<<"Give me two verbals, like swimming, walking, or hiking:"<<endl;
getline(cin, verbal1);
getline(cin, verbal2);
cout<<"Give me some animals:"<<endl;
getline(cin, animal1);
getline(cin, animal2);
cout<<"How about a male friend or family member:"<<endl;
getline(cin, name1);
cout<<"Now how about a female friend or family member:"<<endl;
getline(cin, name2);
cout<<"A famous male movie star:"<<endl;
getline(cin, name4);
cout<<"Female movie star:"<<endl;
getline(cin, name5);
cout<<"Someone/something that is dead:"<<endl;
getline(cin, name3);
cout<<"What does the animal you picked eat? Don't know? What do YOU eat?"<<endl;
getline(cin, food1);
cout<<"What sound does your animal make?"<<endl;
getline(cin, sound1);
cout<<"What do you do to make others feel pain? (past tense)"<<endl;
getline(cin, fight1);
cout<<"Where on earth do you think is the worst place to live?"<<endl;
getline(cin, place1);
cout<<"Where is a place no one would ever find you?"<<endl;
getline(cin, place2);
cout<<"Where do you live?"<<endl;
getline(cin, place3);
cout<<"Where do you want to live?"<<endl;
getline(cin, place4);
cout<<"What is a synomyn for the word \"hole\"?"<<endl;
getline(cin, hole1);
cout<<"Something you find in almost every household:"<<endl;
getline(cin, object1);
cout<<"What are a few ways you can get from place to place? (past tense)"<<endl;
getline(cin, transport1);
getline(cin, transport2);
cout<<"What are some things you could call a newspaper? (Gazetter, Press, Times, etc.)"<<endl;
getline(cin, newspaper1);
cout<<"What is something you couldn't live without? Can be literal or sentimental:"<<endl;
getline(cin, object1);
cout<<"Give me what you call a female relative, like a sister or even a second cousin:"<<endl;
getline(cin, relative1);
cout<<"Give me a race, eg. Russian, Chinese, American, British, ect. :"<<endl;
getline(cin, race1);
cout<<"Give me any number, any number, high or low, just not negative:"<<endl;
getline(cin, no1);
cout<<"Give me a body part (masculine):"<<endl;
getline(cin, bodypart1);
cout<<endl;
cout<<" The very "<<adjective1<<" and "<<adjective2<<" man was "<<name1<<". "<<name1<<" had just finished his "<<verbal1<<" lessons";
cout<<" and was very "<<adjective3<<". "<<name1<<"'s pet "<<animal1<<", "<<name2<<", had just finished her "<<verbal2<<" lessons. They both";
cout<<" decided to hit the "<<food1<<"."<<endl;
cout<<" "<<name2<<" woke "<<name1<<" with a "<<sound1<<" that could've waken "<<name3<<". He flung out of bed and "<<fight1<<" "<<name2<<" as hard as he could.";
cout<<" "<<name2<<" didn't stir. She was DEAD! "<<name1<<" quickly threw her body in a "<<hole1<<" and ran away to "<<place1<<". He disliked it so much he almost threw a "<<object1<<" out the window.";
cout<<" But then he thought up a devilish plot: he "<<transport1<<" to "<<place2<<" and from there "<<transport2<<" to "<<place3<<" where he found "<<name4<<", his new accomplice. Soon after "<<name1<<" and "<<name4;
cout<<"THERE USED TO BE MORE - NEEDED TO DELETE FOR THIS TO FIT IN THE POST";
system("PAUSE");
return 0;
}


The main problem is I can't get them to work together, and I've looked at many tutorials on multi-file projects and how to get them to work, but I don't know how to do whatever needs to be done to make these work in conjunction.

I'm using Visual C++ Express as my compiler.

Any Ideas?