Compilation failed

I’m new to coding in general, but I went for this anyway. I was following the coin lip tutorial, and halfway through I was told to do truffle compile. I ran the code in the terminal and It comes back to this every time.

I changed my version in truffle-config.js multiple times and also in flipcontract.sol I don’t know what to do. Can someone give me a simple explanation on what to do?

The Coin Flip tutorial is not a beginner tutorial. I’d recommend starting with:
https://docs.moralis.io/guides/build-a-simple-dapp-in-3-minutes

At the top of every Solidity file you must declare which version (or versions) of Solidity the code should be compiled with. All files imported in your project must also declare this AND must specify they support that same version.

Next you need to tell Truffle which compiler version to use. This must also be the same.

The flipcontract.sol file declares any version between 0.7.5 and less than 0.8.0 (that’s what the ^ means)

import "../node_modules/@openzeppelin/contracts/access/Ownable.sol";
import "../node_modules/@openzeppelin/contracts/math/SafeMath.sol";

pragma solidity ^0.7.5;

The flipcontract.sol file also imports 2 Solidity files from the @openzeppelin package which if you go into the node_modules directory you can find them and inspect them:

Ownable.sol requires any Solidity version between 0.6.0 and less than 0.8.0… and 0.7.5 is between these values so flipcontract.sol is ok with that.

// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;

The same with SafeMath.sol

// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;

Setting the compiler version in Truffle is done exactly how it’s explained in the link in the error message:

in tuffle-config.js modify the section that looks like this to what is below. This will set the Truffle solc version to 0.7.5.

  // Configure your compilers
  compilers: {
    solc: {
       version: "0.7.5",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      // settings: {          // See the solidity docs for advice about optimization and evmVersion
      //  optimizer: {
      //    enabled: false,
      //    runs: 200
      //  },
      //  evmVersion: "byzantium"
      // }
    }
  }

From here I’d suggest all of “Basics” tutorials. And joining the Academy.

I changed everything in my code to the code you had and to 0.7.5 and it still has compilation failed.

take a look at the full code in the Github repo here perhaps you can spot where yours is different