Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8903063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:46:32+00:00 2026-06-15T01:46:32+00:00

I have a small bit of code I made on Microsoft Visual studio that

  • 0

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;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:46:33+00:00Added an answer on June 15, 2026 at 1:46 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have this small bit of code that generates rows and columns of
I have a small bit of code that runs in an applet that contains
I have a small piece of code that requires to read 4-bit values bitpacked
Using Rails 3.0, I have a small bit of code that I seem to
I have a small bit of code that gets my images from smugmug. My
So, I have a small bit of javascript code that makes a popup div.
I have a simple piece of code, that compiles in Delphi XE2 but not
I am converting a some C++ to java and have a small bit that
I have this small snippet to change a bit of html when a user
I have small web app that generate PDF files as a report. I'm trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.