This is my first year of BIT and im doing C++ for first year atm.
Now i have this assignment which is i have to generate random number, and prompt the user to quess the number. when they quest it right i have to prompt that they are right and ask if they want to plau again. i have to put it into function call here is the requirement. "For each quess entered by the user, the program should call a funtion to determine wether the random number is greater or smaller than the user's quess. Here is my complete code so far without function call.

//---------------------------------------------------------------------------
#include <iostream>
#include <conio>
#include <cstdlib>
#include <iomanip>
#include <ctime>
#pragma hdrstop
using namespace std;

#include <tchar.h>
//---------------------------------------------------------------------------

#pragma argsused
int main()
{
    int answer;
    int quess;
    char playAgain;

    srand( time( 0 ) );
    answer = 1 + rand() % 10;
    cout << "Quess a number from 1 to 10: ";
    cin >> quess;
    while ( quess != answer )
    {
        if ( quess > answer )
        {
            cout << "Too high. try again: ";
            cin >> quess;
        }
        else
            if ( quess < answer )
            {
                cout << "too low. try again: ";
                cin >> quess;
            }
    }
    cout << answer << "\nExcellent quess!" << "\nPlayagain?(Y|N)?: ";
    cin >> playAgain;
    while ( playAgain == 'y' || playAgain == 'Y' )
    {
        srand( time( 0 ) );
        answer = 1 + rand() % 10;

        cout << "Quess a number from 1 to 10: ";
        cin >> quess;
        while ( quess != answer )
        {
            if ( quess > answer )
            {
                cout << "Too high. try again: ";
                cin >> quess;
            }
            else
                if ( quess < answer )
                {
                    cout << "too low. try again: ";
                    cin >> quess;
                }
        }
        cout << answer << "\nNice! playagain?(Y|N)?: ";
        cin >> playAgain;
    }

    return 0;
}
//---------------------------------------------------------------------------

And here is the programe with function but it does not meet the requirement.

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include <iostream>
#include <conio>
#include <cstdlib>
#include <iomanip>
#include <ctime>
#pragma hdrstop
using namespace std;

#include <tchar.h>

char funtionCall( char, int, int );

//---------------------------------------------------------------------------
#pragma argsused
int main()
{
    char playAgain;
    int answer;
    int quess;

    srand( time( 0 ) );
    answer = 1 + rand() % 10;
    cout << "Quess a number from 1 to 10: ";
    cin >> quess;

    functionCall( playAgain, answer, quess );
    while ( playAgain == 'y' || playAgain == 'Y' )
    {
        srand( time( 0 ) );
        answer = 1 + rand() % 10;

        cout << "Quess a number from 1 to 10: ";
        cin >> quess;
        while ( quess != answer )
        {
            if ( quess > answer )
            {
                cout << "Too high. try again: ";
                cin >> quess;
            }
            else
                if ( quess < answer )
                {
                    cout << "too low. try again: ";
                    cin >> quess;
                }
        }
        cout << answer << "\nNice! playagain?(Y|N)?: ";
        cin >> playAgain;
    }

    return 0;
}
//---------------------------------------------------------------------------
//
//
//
/
//---------------------------------------------------------------------------
char funtionCall( char playAgain, int answer, int quess )
{
    while ( quess != answer )
    {
        if ( quess > answer )
        {
            cout << "Too high. try again: ";
            cin >> quess;
        }
        else
            if ( quess < answer )
            {
                cout << "too low. try again: ";
                cin >> quess;
            }
    }
}
//---------------------------------------------------------------------------

Please any idea i can put it into function call!

Edited 3 Years Ago by Reverend Jim: Fixed formatting

Can't read the darn thing! Did you bother to read any of the requested information posted all over this site about CODE tags, like
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used, even in responses to your posts
6) Even on the background of the box you actually typed your message in

This article has been dead for over six months. Start a new discussion instead.