TDM GCC 4.9.2 not functioning properly on Windows 10 64-bit
Microsoft C++ Compiler (MSVS) runs smoothly
I tried to use file handling in a c++ source file.
The file's purpose was to read a .txt file called ClientList.txt
and write the contents
to a new file called ClientListv2.txt while modifying the pre-existing data.
Here's the contents of the .txt file ClientList.txt:
George A Harrison 713-555-1234 gaharrison#gmail.com 250 N Main Street, Baytown, TX
James K Smith 713-555-1235 jksmith#gmail.com 100 Cactus St, Baytown, TX
Alma P Sanchez 713-554-1237 apsanchez#gmail.com 312 Luella Blvd, Pasadena, TX
Samantha J Jones 713-554-1238 sjjones#gmail.com 125 Purdue Ln, Pasadena, TX
Paula Mary Henry 713-553-1239 pmhenry#gmail.com 412 Colorado Ave, League City, TX
Henry B Albertson 713-553-2345 hbalbertson#gmail.com 724 Perkins Ave, League City, TX
Samuel * Harrison 713-552-2346 sharrison#gmail.com 200 Wesley Ln, Deer Park, TX
Peter N Smith 713-552-2347 pnsmith#gmail.com 157 Briarwood Ct, Deer Park, TX
James Edward Bennett 713-551-2348 jebennett#gmail.com 330 S 6th St, La Porte, TX
Javier D Rodriquez 713-551-2349 jdrodriquez#gmail.com 245 Parkcrest Dr, La Porte, TX
The task was to create a duplicate file called ClientListv2.txt which contains all the pre-existing
information, with two addional records, as well as a change to the phone number and address of any one single line. (record)
Here's my attempt to do the process in C++:
//I started out by included my header files:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
//reading the file
fstream file;
file.open("ClientList.txt", ios::in | ios::out);
if (!file.is_open())
{
cout << "File does not exist" << endl;
exit(0);
}
char FirstName[10];
char MiddleName[10];
char LastName[15];
char Phone[15]; //one extra char for '\0' (string terminal char)
char Email[31];
char Address_num[8];
char Address_street[25];
char Town[25];
char State[8];
while (file.good())
{
file.getline(FirstName, 9, ' ');
file.getline(MiddleName, 9, ' ');
file.getline(LastName, 14, ' ');
file >> ws;
file.getline(Phone, 14, ' ');
file >> ws;
file.getline(Email, 30, ' ');
file >> ws;
file.getline(Address_num, 7, ' ');
file >> ws;
file.getline(Address_street, 24, ',');
file >> ws;
file.getline(Town, 24, ',');
file >> ws;
file.getline(State, 7);
file.clear();
file >> ws;
cout << FirstName << " " << MiddleName << " " << LastName << " " << Phone << " " << Email << " " << Address_num << " " << Address_street << " " << Town << " " << State << endl;
}
//To modify one phone and one street address of any single record(line), I used this approach...
fstream new_file;
new_file.open("ClientListv2.txt", ios::out | ios::in);
//file.clear();
file.seekg(0, ios::beg);
file.seekp(0, ios::beg);
char c;
while (file.good())
{
file.get(c);
new_file << c;
}
//declaring a string to take a whole line
string line;
int line_num;
//go to the beginning of the new_file
new_file.seekg(0, ios::beg);
new_file.seekp(0, ios::beg);
cout << "Enter Line No to Edit Phone Number (First Line is 1): " << endl;
cin >> line_num;
for (int i = 1; i < line_num; i++)
{
getline(new_file, line);
}
new_file.seekp(22, ios::cur);
new_file << "888-888-8888";
cout << new_file.tellp() << endl;
cout << new_file.tellg() << endl; //34
cout << new_file.tellp() << endl;
new_file.seekg(0, ios::beg); //moving the flag pointers to the beginning of the file
new_file.seekp(0, ios::beg);
cout << "Enter Line No to Edit Street Address (First Line is 1): " << endl;
cin >> line_num;
for (int i = 1; i < line_num; i++)
{
getline(new_file, line);
}
//65 street address
new_file.seekp(64, ios::cur);
new_file << "B Tane Stripe"; //any address you want to add
cout << new_file.tellg() << endl; //78
cout << new_file.tellp() << endl;
//move the file markers to the end of the file
new_file.seekg(0, ios::end);
new_file.seekp(0, ios::end);
cout << "\t\t\tUpdating Client List Text File\t\t\t" << endl;
//two add two addional clients
cout << "\nEnter the first addional record:\n";
cout << "Enter the FirstName" << endl;
cout << "Enter the MiddleName" << endl;
cout << "Enter the LastName" << endl;
cout << "Enter the Phone" << endl;
cout << "Enter the Email" << endl;
cout << "Enter the Address_num" << endl;
cout << "Enter the Address_street" << endl;
cout << "Enter the Town" << endl;
cout << "Enter the State" << endl;
cin >> FirstName;
cin >> MiddleName;
cin >> LastName;
cin >> Phone;
cin >> Email;
cin >> Address_num;
cin.ignore();
cin.getline(Address_street, 24);
cin.getline(Town, 24);
cin >> State;
new_file.clear();
new_file << "\n" << FirstName << " " << MiddleName << " " << LastName << " " << Phone << " " << Email << " " << Address_num << " " << Address_street << " " << Town << " " << State << endl;
cout << "\nEnter the second addional record:\n";
cout << "Enter the FirstName" << endl;
cout << "Enter the MiddleName" << endl;
cout << "Enter the LastName" << endl;
cout << "Enter the Phone" << endl;
cout << "Enter the Email" << endl;
cout << "Enter the Address" << endl;
cout << "Enter the Town" << endl;
cout << "Enter the State" << endl;
cin >> FirstName;
cin >> MiddleName;
cin >> LastName;
cin >> Phone;
cin >> Email;
cin >> Address_num;
cin.ignore();
cin.getline(Address_street, 24);
cin.getline(Town, 24);
cin >> State;
new_file << FirstName << " " << MiddleName << " " << LastName << " " << Phone << " " << Email << " " << Address_num << " " << Address_street << " " << Town << " " << State << endl;
file.close();
new_file.close();
return 0;
}
Brief Summary
After doing all of this, I've noticed that first, my code only works when I have a ClientListv2.txt manually created in my
present working directory. If not, the code doens't generate a new .txt file itself. Secondly, using a TDM GCC 4.9.2 Compiler, I get pretty strange pattern-based
sequences of outputs when examing my phone number and address accross multiple lines.
It appears, that the code overwrites some of the old text and sometimes it overwrites none of it.
For some reason, when I tried compiling and running it on Visual Studio (Microsoft C++ Compiler MSVC), I got the right results.
Why is TDM GCC 4.9.2 acting like that?
My machine runs Windows 10 64-bit. I suppose that the '\r\n' might have something responsible for this strange output. Who knows?
I used the following dummy text to input the values for two additional rows:
Sam
Billy
Jhons
299-292-9292
sambilly#gmail.com
39
2nd Street
Ventnor
NJ
Related
I am trying to create a text generator which shall generate following output:
localparam OR_CHANNEL_DATA_WIDTH = 2;
localparam RQ_CHANNEL_DATA_WIDTH = 18;
localparam RSP_CHANNEL_DATA_WIDTH = 8;
localparam VIN_CHANNEL_DATA_WIDTH = 43;
localparam VOUT_CHANNEL_DATA_WIDTH = 123;
I used std::stringstream to build the stream:
std::stringstream ss;
ss << "localparam OR_CHANNEL_DATA_WIDTH" << std::right << std::setw(80) << " = " << Sth::get() << ";\n";
ss << "localparam RQ_CHANNEL_DATA_WIDTH" << std::right << std::setw(80) << " = " << Sth::get() << ";\n";
ss << "localparam RSP_CHANNEL_DATA_WIDTH" << std::right << std::setw(80) << " = " << Sth::get() << ";\n";
Sth::get() will return number. There are many such lines that needs to be generated. But the text in the middle is not fixed. How can I achieve the above output
I am not sure you can do it in a simple streaming operation, but easily write a small function that does the job:
#include <iostream>
#include <sstream>
#include <iomanip>
const std::string adjust_width(const std::string& s, int width)
{
std::stringstream temp;
temp << std::left << std::setw(width) << s;
return temp.str();
}
int main()
{
std::stringstream ss;
ss << adjust_width("localparam OR_CHANNEL_DATA_WIDTH", 80) << " = " << 1 << ";\n";
ss << adjust_width("localparam RQ_CHANNEL_DATA_WIDTH", 80) << " = " << 12 << ";\n";
ss << adjust_width("localparam RSP_CHANNEL_DATA_WIDTH", 80) << " = " << 123 << ";\n";
ss << adjust_width("localparam VIN_CHANNEL_DATA_WIDTH", 80) << " = " << 1234 << ";\n";
std::cout << ss.str();
return 0;
}
I have created 2 Publishers connecting to the same static location .
Publisher1
dummyFrontEnd::dummyFrontEnd():context(1),socket(context,ZMQ_PUB) {
}
void dummyFrontEnd::Init()
{
socket.connect("tcp://127.0.0.1:5555");
cout << "Connecting .... " << endl;
}
void dummyFrontEnd::SendTwoTables()
{
cout << "In SendTwoTables" <<endl;
while(1) {
canlogreq canLogObj = canlogreq::default_instance();
canLogObj.set_fromhours(11);
canLogObj.set_fromminutes(7);
canLogObj.set_fromseconds(2);
canLogObj.set_fromday(16);
canLogObj.set_frommonth(5);
canLogObj.set_fromyear(2020);
canLogObj.set_tohours(12);
canLogObj.set_tominutes(7);
canLogObj.set_toseconds(4);
canLogObj.set_today(17);
canLogObj.set_tomonth(5);
canLogObj.set_toyear(2020);
zmq::message_t logsnippetmsg(canLogObj.ByteSizeLong() + sizeof(uint16_t));
*((uint16_t*)logsnippetmsg.data()) = 20;
canLogObj.SerializeToArray(logsnippetmsg.data()+sizeof(uint16_t), canLogObj.ByteSizeLong());
socket.send(logsnippetmsg);
usleep(1);
canLogObj.clear_fromhours();
canLogObj.clear_fromminutes();
canLogObj.clear_fromseconds();
canLogObj.clear_fromday();
canLogObj.clear_frommonth();
canLogObj.clear_fromyear();
canLogObj.clear_tohours();
canLogObj.clear_tominutes();
canLogObj.clear_toseconds();
canLogObj.clear_today();
canLogObj.clear_tomonth();
canLogObj.clear_toyear();
}
}
Publisher2:
dummyFrontEnd::dummyFrontEnd():context(1),socket(context,ZMQ_PUB) {
}
void dummyFrontEnd::Init()
{
socket.connect("tcp://127.0.0.1:5555");
cout << "Connecting .... " << endl;
}
void dummyFrontEnd:: SendData() {
while (std::getline(file, line_str)) {
std::stringstream ss(line_str);
double tdiff;
int i;
char J;
int _1939;
int pgn;
char p;
int priority;
char _0;
int source;
char dash;
std::string direction;
char d;
int length;
int data[8];
ss >> tdiff >> i >> J >> _1939 >> pgn >> p >> priority >> _0 >> source
>> dash >> direction >> d >> length >> data[0] >> data[1] >> data[2]
>> data[3] >> data[4] >> data[5] >> data[6] >> data[7];
timestamp += tdiff;
while (gcl_get_time_ms() - start_time <
uint64_t(timestamp * 1000.0) - first_time) { usleep(1); }
if (arguments.verbose) {
std::cout << timestamp << " " << i << " " << J << " " << _1939 << " "
<< pgn << " " << p << " " << priority << " " << _0 << " " << source
<< " " << dash << " " << direction << " " << d << " " << length
<< " " << data[0] << " " << data[1] << " " << data[2] << " "
<< data[3] << " " << data[4] << " " << data[5] << " " << data[6]
<< " " << data[7] << std::endl;
}
uint64_t timestamp_ms = (uint64_t)(timestamp * 1000.0);
protoTable.add_columnvalues(uint64ToString(timestamp_ms) /* timestamp */);
protoTable.add_columnvalues(intToString(pgn) /* PGN */);
protoTable.add_columnvalues(intToString(priority) /* Priority */);
protoTable.add_columnvalues(intToString(source) /* Source */);
protoTable.add_columnvalues(direction /* Direction */);
protoTable.add_columnvalues(intToString(length) /* Length */);
protoTable.add_columnvalues(intToString(data[0]) /* data1 */);
protoTable.add_columnvalues(intToString(data[1]) /* data2 */);
protoTable.add_columnvalues(intToString(data[2]) /* data3 */);
protoTable.add_columnvalues(intToString(data[3]) /* data4 */);
protoTable.add_columnvalues(intToString(data[4]) /* data5 */);
protoTable.add_columnvalues(intToString(data[5]) /* data6 */);
protoTable.add_columnvalues(intToString(data[6]) /* data7 */);
protoTable.add_columnvalues(intToString(data[7]) /* data8 */);
zmq::message_t create_values(protoTable.ByteSizeLong()+sizeof(uint16_t));
*((uint16_t*)create_values.data()) = TABLEMSG_ID; // ID
protoTable.SerializeToArray(create_values.data()+sizeof(uint16_t), protoTable.ByteSizeLong());
socket.send(create_values);
protoTable.clear_columnvalues();
usleep(1);
}
}
Subscriber
TransportLayer::TransportLayer():context(1),socket(context,ZMQ_SUB){ }
void TransportLayer::Init()
{
socket.bind("tcp://*:5555");
socket.setsockopt(ZMQ_SUBSCRIBE, "", 0);
}
void TransportLayer::Receive()
{
cout <<"TransportLayer::Receive " << " I m in server " << endl;
static int count = 1 ;
// Producer thread.
while ( true ){
zmq::message_t request;
string protoBuf;
socket.recv(&request);
uint16_t id = *((uint16_t*)request.data());
cout <<"TransportLayer : "<<"request.data: "<< request.data() << endl;
cout << "TransportLayer: count " << count<< endl; count = count+1 ;
cout <<"TransportLayer : request.data.size "<< request.size() << endl;
protoBuf = std::string(static_cast<char*>(request.data()+sizeof(uint16_t)), request.size()-sizeof(uint16_t));
cout << "ProtoBuf : " << protoBuf << endl;
InterfaceLayer *interfaceLayObj = InterfaceLayer::getInstance();
switch(id) {
case TABLEMSG_ID: cout << "Canlyser" << endl;
interfaceLayObj->ParseProtoBufTable(protoBuf);
break;
case LOGSNIPPET_ID:cout << "LogSnip" << endl;
interfaceLayObj->ParseProtoBufLogSnippet(protoBuf);
interfaceLayObj->logsnippetSignal(); // publish the signal
break;
default:
break;
}
usleep(1);
}
}
Observation :
I)
Execution Order .
1. Started Subscriber
2. Started Publisher1 ( it sent only one data value)
Subscriber missed to receive this data.
II) modified Publisher1 to send the same data in a while loop
Execution Order
1. Started Subscriber
2. Started Publisher1
3. Started Publsiher2 .
Now I see that Subscriber is receiving the data from both publishers .
This gives me an indication that there is a possibility for data loss.
How do I ensure there is absolutely no data loss.
Thanks
Your producer may be sending its one message before the subscription handshaking has completed. As a result, the publish socket discards the message because there is no subscription registered.
If you use an XPUB socket (ZMQ_XPUB -- see http://api.zeromq.org/4-2:zmq-socket) instead of a PUB socket, your program can wait for a subscribe message, so that it knows that someone is listening, before sending its message(s).
I have searched countless forums and websites but I can't seem to find the answer. I'm trying to use SetConsoleTextAttribute but it only affects the text. How can I affect the whole screen like the command color 1f would? My code is:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <wincon.h>
using namespace std;
int main()
{
SetConsoleTitle("C++ CALCULATOR"); // Title of window
int x; // Decision
int a; // First Number
int b; // Second Number
int c; // Answer
HANDLE Con;
Con = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(Con, BACKGROUND_BLUE | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
cout << "CALCULATOR" << endl << endl;
cout << "1:ADDITION" << endl << "2:SUBTRACTION" << endl << "3:MULTIPLICATION";
cout << endl << "4:DIVISION" << endl << "5:EXIT" << endl;
cin >> x;
switch (x)
{
case 1: // Addition code
cout << endl << "ADDITION" << endl << "FIRST NUMBER:";
cin >> a;
cout << endl << "SECOND NUMBER:";
cin >> b;
c = a + b;
cout << endl << "ANSWER:" << c;
break;
case 2: // Subtraction code
cout << endl << "SUBTRACTION" << endl << "FIRST NUMBER:";
cin >> a;
cout << endl << "SECOND NUMBER:";
cin >> b;
c = a - b;
cout << endl << "ANSWER:" << c;
break;
case 3: // Multiplication code
cout << endl << "MULTIPLICATION" << endl << "FIRST NUMBER:";
cin >> a;
cout << endl << "SECOND NUMBER:";
cin >> b;
c = a * b;
cout << endl << "ANSWER:" << c;
break;
case 4: // Division code
cout << endl << "DIVISION" << endl << "FIRST NUMBER:";
cin >> a;
cout << endl << "SECOND NUMBER:";
cin >> b;
c = a / b;
cout << endl << "ANSWER:" << c;
break;
case 5: // Exit code
return 0;
}
}
This solution relies on these WinAPI functions and structures:
GetConsoleScreenBufferInfo to get screen dimensions
FillConsoleOutputAttribute to fill screen with an attribute
CONSOLE_SCREEN_BUFFER_INFO structure to store screen information
The code is as follows:
HANDLE hCon;
CONSOLE_SCREEN_BUFFER_INFO csbiScreenInfo;
COORD coordStart = { 0, 0 }; // Screen coordinate for upper left
DWORD dwNumWritten = 0; // Holds # of cells written to
// by FillConsoleOutputAttribute
DWORD dwScrSize;
WORD wAttributes = BACKGROUND_BLUE | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
hCon = GetStdHandle(STD_OUTPUT_HANDLE);
// Get the screen buffer information including size and position of window
if (!GetConsoleScreenBufferInfo(hCon, &csbiScreenInfo))
{
// Put error handling here
return 1;
}
// Calculate number of cells on screen from screen size
dwScrSize = csbiScreenInfo.dwMaximumWindowSize.X * csbiScreenInfo.dwMaximumWindowSize.Y;
// Fill the screen with the specified attribute
FillConsoleOutputAttribute(hCon, wAttributes, dwScrSize, coordStart, &dwNumWritten);
// Set attribute for newly written text
SetConsoleTextAttribute(hCon, wAttributes);
The inline comments should be enough to understand the basics of what is going with the supplied documentation links. We get the screen size with GetConsoleScreenBufferInfo and use that to determine the number of cells on the screen to update with a new attribute using FillConsoleOutputAttribute . We then use SetConsoleTextAttribute to ensure that all new text that gets printed matches the attribute we used to color the entire console screen.
For brevity I have left off the error check for the calls to FillConsoleOutputAttribute and SetConsoleTextAttribute. I put a stub for the error handling for GetConsoleScreenBufferInfo . I leave it as an exercise for the original poster to add appropriate error handling if they so choose.
SetConsoleTextAttribute changes the attribute for new characters that you write to the console, but doesn't affect existing contents of the console.
If you want to change the attributes for existing characters already being displayed on the console, use WriteConsoleOutputAttribute instead.
I'm trying to create a program that outputs the vin, gallons, miles, and mpg of a car to a text file using ofstream.
outfile << setw(8) << "VIN" << setw(19) << "Miles" << setw(10) << "Gallons" << setw(6) << "MPG" << "\n" << "---------------------------------------------\n" << vin(0) << setw(10) << miles(0) << setw(6) << gallons(0) << setw(11) << fixed << showpoint << setprecision(1) << static_cast<double>(miles(0))/gallons(0)<< "\n" << vin(1) << setw(10) << miles(1) << setw(6) << gallons(1) << setw(11) << static_cast<double>(miles(1))/gallons(1) << "\n" << vin(2) << setw(10) << miles(2) << setw(6) << gallons(2) << setw(11) << static_cast<double>(miles(2))/gallons(2) << "\n" << vin(3) << setw(10) << miles(3) << setw(6) << gallons(3) << setw(11) << static_cast<double>(miles(3))/gallons(3) << "\n" << vin(4) << setw(10) << miles(4) << setw(6) << gallons(4) << setw(11) << static_cast<double>(miles(4))/gallons(4) << endl;
Is there a simpler way to accomplish this without having to repeat for each new row? Thanks.
First thing's first, you should object-orient your code to keep it concise. This means by preference keeping the vin, gallons, miles, and mpg as data members of a class.
struct Car
{
// ...
int vin, gallons, miles, mpg;
};
Then you can implement stream inserters/extractors for input and output. Create and put your Car elements in a std::vector<Car> and iterate through them to read or write them to standard input/output.
Ultimately, the line above should be transformed into:
for (const auto& c : cars)
{
std::cout << c << std::endl;
}
I have a small bit of code I made on Microsoft Visual studio that is a simple program I used to teach someone the fundamentals of C++. I am moving to Xcode and it is new to me. I need help reformatting this code so it can be run on a mac. Please help!
#include <iostream>
#include <string>
#include <random> //this needs to be included for the rand() function
#include <time.h> //this needs to be included for the seed time
#include <windows.h>
#include <conio.h>
using namespace std;
//PAB
int random_in_range(int a, int b)//this function will generate a random number between specified range
{
return (a+rand()%(b-a+1));
}
void hangman(){
char guess;
string word="";
string hidden ="";
int strikesLeft= 0;
int random = random_in_range(1,15);
switch(random){
case 1:
word = "bacon";
hidden ="?????";
strikesLeft=5;
break;
case 2:
word = "computer";
hidden ="????????";
strikesLeft=7;
break;
case 3:
word = "human";
hidden = "?????";
strikesLeft=7;
break;
case 4:
word = "desk";
hidden = "????";
strikesLeft=7;
break;
case 5:
word = "card";
hidden = "????";
strikesLeft=7;
break;
case 6:
word="keyboard";
hidden = "????????";
strikesLeft=7;
break;
case 7:
word="phone";
hidden="?????";
strikesLeft=7;
break;
case 8:
word="mouse";
hidden="?????";
strikesLeft=7;
break;
case 9:
word="camp";
hidden="????";
strikesLeft=7;
break;
case 10:
word="captain";
hidden="???????";
strikesLeft=7;
break;
case 11:
word="brother";
hidden="???????";
strikesLeft=7;
break;
case 12:
word="beauty";
hidden="??????";
strikesLeft=7;
break;
case 13:
word="cave";
hidden="????";
strikesLeft=7;
break;
case 14:
word="children";
hidden="????????";
strikesLeft=7;
break;
case 15:
word="action";
hidden="??????";
strikesLeft=7;
break;
}
bool gameOver=false;
int pos;
//add strike counter
cout << " ***WELCOME TO HANGMAN***" << endl << endl;
cout << "Try to guess the word in question marks. But watch out, if you use too many letters not in the word, you will lose." << endl;
cout << "You start with " << strikesLeft << " strikes." << endl;
cout << "Good luck..." << endl;
do{
cout << "Word is " << hidden << endl << endl;
cout << "Enter guess: ";
cin >> guess;
pos = word.find_first_of(guess);
if(pos!=-1)
hidden[pos]=guess;
else{
strikesLeft--;
cout <<"Sorry, " << guess << " is not in this word." << endl;
cout <<"You have " << strikesLeft << " strikes left." << endl; //also tell them strikes remaining
}
if(hidden==word || strikesLeft==0)
gameOver=true;
}
while(gameOver==false);
if(strikesLeft==0)
cout << "Game Over! You failed..." << endl;
cout << "The word was " << word << "." << endl;
if(strikesLeft>0)
cout << "Congrats! You completed my game with " << strikesLeft << " strikes left." << endl;
system("PAUSE");
}
int main(){
cout << "" << endl << endl << endl << endl << endl << endl << endl;
cout << " *WELCOME*" << endl;
system("color 0c");
Sleep(500);
cout << " **TO**" << endl;
system("color 0f");
Sleep(500);
cout << " ***PAB***";
system("color 0a");
Sleep(3000);
system("cls");
cout << "" << endl << endl << endl << endl << endl << endl << endl;
cout << " P";
Sleep(100);
cout << "E";
Sleep(100);
cout << "R";
Sleep(100);
cout << "S";
Sleep(100);
cout << "O";
Sleep(100);
cout << "N";
Sleep(100);
cout << "A";
Sleep(100);
cout << "L";
Sleep(1000);
cout << " A";
Sleep(100);
cout << "W";
Sleep(100);
cout << "E";
Sleep(100);
cout << "S";
Sleep(100);
cout << "O";
Sleep(100);
cout << "M";
Sleep(100);
cout << "E";
Sleep(1000);
cout << " B";
Sleep(150);
cout << "O";
Sleep(150);
cout << "T";
Sleep(2000);
system("cls");
system("color 08");
cout << "Program loading.";
Sleep(500);
system("cls");
cout << "Program loading..";
Sleep(500);
system("cls");
cout << "Program loading...";
Sleep(500);
system("cls");
cout << "Program loading.";
Sleep(500);
system("cls");
cout << "Program loading..";
Sleep(500);
system("cls");
cout << "Program loading...";
Sleep(500);
system("cls");
cout << "Program loading.";
Sleep(500);
system("cls");
cout << "Program loading..";
Sleep(500);
system("cls");
srand(time(NULL));//seeds the random number generator. Do this before calling the randomInRange function
string name;
int friends;
int DecimalArray[] = {1,2,3,4,5,22,555,85,18,741}; //Create an array of decimal numbers.
system ("color 0f");
cout << "Enter name: ";
cin >> name;
cout << "Hi " << name << "." << " My name is PAB, your personal awesome bot." << endl;
cout << "Now tell me, how many friends do you have? " << endl;
cin >> friends;
if(friends >=75 && friends <300)
cout << "Gee, " << friends << " friends is a lot. But you could always have one more...ME!!" << endl;
if(friends >300)
cout << "Yeah, maybe on Facebook...But we should still be friends!" << endl;
if(friends <75)
cout << "Man, you totally need more friends. I can be one of them!" << endl;
int randomNum=random_in_range(1,50);
int numGuess;
cout << "Now that we're friends, I want to play a game. Now, pick a number between 1 and 50. " << endl;
do{ //dowhile loop using "getting closer" for when your getting closer to the number
cin >> numGuess;
if(numGuess >50)
cout << "Can you read? It clearly says between 1 and 50. " << endl;
if(numGuess >randomNum)
cout << "That's too high guess again. " << endl;
if(numGuess <randomNum)
cout << "That's too low please guess again. " << endl;
}while(numGuess !=randomNum);
system("cls");
cout << "Congratulations! You found out my number." << endl;
cout << "Okay, I agree that was stupid. But, I have another game!" << endl << endl << endl;
hangman();
system("cls");
cout << "Thanks for playing with me today! I hope you had fun." << endl;
cout << "In the future I will have new games and jokes." << endl << endl << endl << endl << endl << endl;
cout << " THE END" << endl;
Sleep(5000);
system("cls");
system("color 08");
cout << "v1.7" << endl;
cout << "[copyright]" << endl;
cout << "Ethan MacCumber 2012" << endl;
system("PAUSE");
return 0;
}
Your major problem is that your code isn't entirely standard C++. You used C++ code that is only available on Windows, the functions in the windows.h and conio.h header files. Any functions in those header files won't work on a Mac.
If you want your code to run on Mac OS X, comment out the includes of windows.h and conio.h. Commenting out the includes of the Windows-specific headers will generate a ton of compiler errors, which should show you where the Windows-specific code is. Get rid of that code and stick with code that is standard C++, like cin and cout. From a quick glance at your code, the calls to Sleep() and System("cls") won't work on a Mac.