contract BitProCoinX is StandardToken, owned {



    /* Public variables of the token */

    /*
    NOTE:
    The following variables are OPTIONAL vanities. One does not have to include them.
    They allow one to customise the token contract & in no way influences the core functionality.
    Some wallets/interfaces might not even bother to look at this information.
    */
    string public name;                   //fancy name: eg Simon Bucks
    uint8 public decimals;                //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
    string public symbol;                 //An identifier: eg SBX
    string public version = 'H1.0';       //human 0.1 standard. Just an arbitrary versioning scheme.
    uint256 public sellPrice; //in wei
    uint256 public buyPrice;  //in wei
    uint256 remaining;
     uint public numInvestors;
  struct Investor {
    uint amount;
    address eth_address;
    bytes32 Name;
    bytes32 email;
    bytes32 message;
  }
  mapping(uint => Investor) public investors;

//
// CHANGE THESE VALUES FOR YOUR TOKEN
//

//make sure this function name matches the contract name above. So if you're token is called TutorialToken, make sure the //contract name above is also TutorialToken instead of ERC20Token

    function BitProCoinX(
        ) public{
        balances[msg.sender] = 1000000000000;               // Give the creator all initial tokens (100000 for example)
        totalSupply = 1000000000000;                        // Update total supply (100000 for example)
        name = "BitProCoinX";                                   // Set the name for display purposes
        decimals = 4;                            // Amount of decimals for display purposes
        symbol = "BPCX";                               // Set the symbol for display purposes
        sellPrice = 7668200000;                         // price of subtoken , i.e. main token price need to be divided by (10 ** uint256(decimals)), here 1000
        buyPrice =  7668200000;                         // price of subtoken , i.e. main token price need to be divided by (10 ** uint256(decimals)), here 1000
        remaining = 0;
        numInvestors;
    }
     function() public payable{
         //if(msg.sender!=owner)
         require(msg.value > 0);
        uint  amount = div(msg.value, buyPrice);                    // calculates the amount
        require(balances[this] >= amount);               // checks if it has enough to sell
        balances[msg.sender] += amount;                  // adds the amount to buyer's balance
        balances[this] -= amount;                        // subtracts amount from seller's balance
        Transfer(this, msg.sender, amount);               // execute an event reflecting the change
        //investors[numInvestors] = Investor(msg.value, msg.sender);
        numInvestors++;
          
    }
    /* Approves and then calls the receiving contract */
    function approveAndCall(address _spender, uint256 _value, bytes _extraData) public returns (bool success) {
        allowed[msg.sender][_spender] = _value;
        Approval(msg.sender, _spender, _value);

        //call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
        //receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
        //it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
        if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
        return true;
    }

    function setPrices(uint256 newSellPriceInwei, uint256 newBuyPriceInwei) onlyOwner {
        sellPrice = div(newSellPriceInwei , (10 ** uint256(decimals)));  
        buyPrice =  div(newBuyPriceInwei , (10 ** uint256(decimals)));
    }
    function buy() payable returns (uint amount){
        require(msg.value > 0);
        amount = div(msg.value, buyPrice);                    // calculates the amount
        require(balances[this] >= amount);               // checks if it has enough to sell
        balances[msg.sender] += amount;                  // adds the amount to buyer's balance
        balances[this] -= amount;                        // subtracts amount from seller's balance
        Transfer(this, msg.sender, amount);               // execute an event reflecting the change
        //investors[numInvestors] = Investor(msg.value, msg.sender);
        numInvestors++;
        return amount;                                    // ends function and returns
    }
    function onlyPay() payable onlyOwner{
        
        
    }

    function sell(uint amount) returns (uint revenue){
        require(balances[msg.sender] >= amount);         // checks if the sender has enough to sell
        balances[this] += amount;                        // adds the amount to owner's balance
        balances[msg.sender] -= amount;                  // subtracts the amount from seller's balance
        revenue = amount * sellPrice;
        require(msg.sender.send(revenue));                // sends ether to the seller: it's important to do this last to prevent recursion attacks
        Transfer(msg.sender, this, amount);               // executes an event reflecting on the change
        return revenue;                                   // ends function and returns
    }

    function withdraw(uint _amountInwei) onlyOwner{
        require(this.balance > _amountInwei);
      require(msg.sender == owner);
      owner.send(_amountInwei);
     
    }
    /* Safe Math Function */
     function mul(uint256 a, uint256 b) internal pure returns (uint256) {
    if (a == 0) {
      return 0;
    }
    uint256 c = a * b;
    assert(c / a == b);
    return c;
  }

  function div(uint256 a, uint256 b) internal pure returns (uint256) {
    // assert(b > 0); // Solidity automatically throws when dividing by 0
    uint256 c = a / b;
    // assert(a == b * c + a % b); // There is no case in which this doesn't hold
    return c;
  }

  function sub(uint256 a, uint256 b) internal pure returns (uint256) {
    assert(b <= a);
    return a - b;
  }

  function add(uint256 a, uint256 b) internal pure returns (uint256) {
    uint256 c = a + b;
    assert(c >= a);
    return c;
  }
    
}
//name this contract whatever you'd like
function BitProCoinX(
    ) public{
    balances[msg.sender] = 1000000000000;               // Give the creator all initial tokens (100000 for example)
    totalSupply = 1000000000000;                        // Update total supply (100000 for example)
    name = "BitProCoinX";                                   // Set the name for display purposes
    decimals = 4;                            // Amount of decimals for display purposes
    symbol = "BPCX";                               // Set the symbol for display purposes
    sellPrice = 7668200000;                         // price of subtoken , i.e. main token price need to be divided by (10 ** uint256(decimals)), here 1000
    buyPrice =  7668200000;                         // price of subtoken , i.e. main token price need to be divided by (10 ** uint256(decimals)), here 1000
    remaining = 0;
    numInvestors;
}

//
// CHANGE THESE VALUES FOR YOUR TOKEN
//
//make sure this function name matches the contract name above. So if you're token is called TutorialToken, make sure the //contract name above is also TutorialToken instead of ERC20Token