Number-guessing game in C++ I created a simple number-guessing game.  Do I need to divide this program into functions?  Please offer suggestions.

#include&lt;iostream&gt;
#include&lt;string&gt;
#include&lt;ctime&gt;

void drawLine(int n, char symbol);
void rules();

int main()
{
    int amount;
    int bettingAmount;
    int guess;
    int dice;
    std::string playerName;

    drawLine(60,'_');
    std::cout &lt;&lt; "\n\n\n\t\tCASINO GAME\n\n\n\n";
    drawLine(60,'_');
    std::cout &lt;&lt; "\n\nEnter Your Name : ";
    std::getline(std::cin, playerName);
    std::cout &lt;&lt; "\n\nEnter Deposit amount to play game : ";
    std::cin &gt;&gt; amount;
    char choice;
    do
    {
        system("cls");
        rules();
        std::cout &lt;&lt; "\n\nYour current balance is $ " &lt;&lt; amount &lt;&lt; "\n";

        do
        {
            std::cout &lt;&lt;playerName&lt;&lt;", enter money to bet ";
            std::cin &gt;&gt; bettingAmount;
            if(bettingAmount &gt; amount)
                std::cout &lt;&lt; "Your betting amount is more than your current balance\n\nRe-enter data\n ";
        }while(bettingAmount &gt; amount);

        do
        {
            std::cout &lt;&lt; "Guess your number to bet between 1 to 10 :";
            std::cin &gt;&gt; guess;
            if(guess &lt;= 0 || guess &gt; 10)
                std::cout &lt;&lt; "Please check the number!! should be between 1 to 10\n\nRe-enter data\n ";
        }while(guess &lt;= 0 || guess &gt; 10);

        srand(time(0));
        dice = rand()%10 + 1;

        if(dice == guess)
        {
            std::cout &lt;&lt; "\n\nGood Luck!! You won Rs." &lt;&lt; bettingAmount * 10;
            amount = amount + bettingAmount * 10;
        }
        else
        {
            std::cout &lt;&lt; "Bad Luck this time !! You lost $ "&lt;&lt; bettingAmount &lt;&lt;"\n";
            amount = amount - bettingAmount;
        }

        std::cout &lt;&lt; "\nThe winning number was : " &lt;&lt; dice &lt;&lt;"\n";
        std::cout &lt;&lt; "\n"&lt;&lt;playerName&lt;&lt;", You have $ " &lt;&lt; amount &lt;&lt; "\n";
        if(amount == 0)
        {
            std :: cout &lt;&lt; "You have no money to play ";
            break;
        }
        std::cout &lt;&lt; "\n\n--&gt;Do you want to play again (y/n)? ";        
        std::cin &gt;&gt; choice;
    }while(choice =='Y'|| choice=='y');

    std::cout &lt;&lt; "\n\n\n";
    drawLine(70,'=');
    std::cout &lt;&lt; "\n\nThanks for playing game. Your balance amount is $ " &lt;&lt; amount &lt;&lt; "\n\n";
    drawLine(70,'=');

    return 0;
}

void drawLine(int n, char symbol)
{
    for(int i=0; i&lt;n; i++)
        std::cout &lt;&lt; symbol;
    std::cout &lt;&lt; "\n" ;
}

void rules()
{
    system("cls");
    std::cout &lt;&lt; "\n\n";
    drawLine(80,'-');
    std::cout &lt;&lt; "\t\tRULES OF THE GAME\n";
    drawLine(80,'-');
    std::cout &lt;&lt; "\t1. Choose any number between 1 to 10\n\t2. If you win you will get 10 times of money you bet\n\t3. If you bet on wrong number you will lose your betting amount\n\n";
    drawLine(80,'-');
}

// END OF PROGRAM
Very good.

A few things I would change:


Declare variables as close to the point of usage as possible.

int amount;
int bettingAmount;
int guess;
int dice;
std::string playerName;


This is very C like to declare all your variables at the top.
By declaring them close to the point of usage you don't need to look around for them they should be close to where you are using them. Also C++ has the concept of construction/destruction on objects which comes in useful and is applies at the point of creation.
Validate that your read worked.

std::cin &gt;&gt; amount;


If the user types in "Kevin" then your whole program will stop working. Any time you have user input it is best to read a line of text (as users interact with the terminal a line at a time). Then parse and validate that data out of line (so that failure does not set the bad bit on the stream (because you will need to reset that).

while(true)
{
    std::string   userInput;
    std::getline(std::cin, userInput);

    std::stringstream userInputStream(userInput);
    if (userInputStream &gt;&gt; amount)
    {
        // The user entered a valid number and not text.
        // 
        // If you care you may want to check that they did not
        // enter text after the number like "10 Bob"
        // Personally I would not bother for version one

        break;   // exit the loop.
    }
    else
    {
        // invalid Input
        std::cerr &lt;&lt; "Invalid Input: Try again\n";
        // Loop re-enters.
        // User trys again.
    }
}

I prefer all sub blocks to have {} around them

if(bettingAmount &gt; amount)
    std::cout &lt;&lt; "Your betting amount is more than your current balance\n\nRe-enter data\n ";  

// I would write like this:
if(bettingAmount &gt; amount)
{
    std::cout &lt;&lt; "Your betting amount is more than your current balance\n\nRe-enter data\n ";
} 


This makes it easier to read. Also when modifying the code and needing to add more statements you don't need to remember to add the {}.
Don't re-seed rand.

srand(time(0));


You only need to do this once in the application. Do it as main() is entered. Don't do it again. It breaks the randomness. It's not required for a simple application like this. But if you want to do better then I would look at using the new random number generates that are part of C++11. It will be good practice (rand() is not very good).


Even so the overall structure is still very C-Like.
You could practice your OO style here.

int main()
{
    Game       game;

    HumPlayer  human;
    while(!human.hadEnough())
    {
        game.play(human);
    }

    CompPlayer computer;
    while(!computer.hadEnough())
    {
        game.play(computer);
    }

    std::cout &lt;&lt; (human.score() &lt; computer.score())
               ? "The time of the computer overlords has arrived.\n";
               : "Still time before this silly machines are smart.\n";
}