0
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;

contract s12 {
    uint public age;
    string public name;
    bool rollno;
    
    constructor() public {
        rollno= false;
    }

    function setname(string memory newName) public {
      name=newName;
    }

    function  getname() public view returns (string){
      return name;
    }

    function setAge(string  memory newAge) public {
      age=newAge;
    }

    function getAge() public view returns(uint){
      return age;
    }
 }

1 Answer 1

1

Two remarks here:

  1. In function getname(), you just need to add memory in the returned value:

    function  getName() public view returns (string memory) {..}
    
  2. You have a type mismatch in function setAge(), as you are assigning newAge (string) to age (uint). The newAge parameter should be uint as well.

    function setAge(uint  newAge) public {
       age = newAge;
    }
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.