Vikash-8090-Yadav / Solidity-Pathshala

One place for the smart contract developer. This repo will have all the smart contract written in the remix ide .It contains all the source code with the screen shot.
MIT License
42 stars 55 forks source link

If-Else Based basic Programs #39

Closed Sanitya7 closed 1 year ago

Sanitya7 commented 2 years ago

Project title

If-Else Programs

Project Description

This file consists of basic program constructed by using conditional statements

contract check_even { function even_odd( uint _num) public pure returns ( int ) { if ( _num % 2 == 0 ){ return 1; } else { return 0; } } }

- Max of Two Integers

// SPDX-License-Identifier: MIT pragma solidity 0.8.0;

contract greattwoCheck { function checkBig( uint _x, uint _y) public pure returns ( uint ) { if ( _x > _y ){ return _x; } else if ( _x == _y ){ return 0; } else { return _y; } } }

- Min of Two Integers

// SPDX-License-Identifier: MIT pragma solidity 0.8.0;

contract getMIN { function get_min( uint _x, uint _y) public pure returns ( uint ) { if ( _x > _y ) { return _y; } else if ( _x < _y ) { return _x; } else { return 0; } } }

- Which Quadrant it is ? 

// SPDX-License-Identifier: MIT pragma solidity 0.8.0;

contract whichQuadrant { function quad( int _x, int _y) public pure returns ( int ) { if ( _x > 0 ){ if ( _y > 0 ){ return 1; } else { return 4; } } if ( _x < 0 ){ if ( _y > 0 ){ return 3; } else { return 2; } } } }

- Min 10 

// SPDX-License-Identifier: MIT pragma solidity 0.8.0;

contract moreThan10 { function getNum( int _num) public pure returns ( int ) { if ( _num > 10 ){ return 1 ; } else { return 0; } } }


- Age Valid for voting or not ?

// SPDX-License-Identifier: MIT pragma solidity 0.8.0;

contract VotingAgeLimit{ uint public Age ; bool public Valid ; //function for checking the age function Check_Age_Limit( uint _x ) public payable returns( bool ){ Age = _x ; if (Age >= 18){ Valid = true ; return Valid; } else { Valid = false ; return Valid ; } } }


- Grade For Students 

// SPDX-License-Identifier: MIT pragma solidity 0.8.0;

contract ScoreCard{ uint public percentage ; string public grade ; //Function for checking the grade at the percentage function giveGrades( uint _percent ) public payable returns( string memory ){ string memory gradeA = 'A'; string memory gradeB = 'B'; string memory gradeC = 'C'; string memory gradeD = 'D'; string memory gradeE = 'E'; percentage = _percent ; if (percentage >= 90 ){ grade = gradeA ; return grade ; } else if ( percentage >= 80 ){ grade = gradeB; return grade ; } else if ( percentage >= 70 ){ grade = gradeC ; return grade ; } else if ( percentage >= 60 ){ grade = gradeD; return grade ; } else { grade = gradeE ; return grade ; } } }


- Bonus For Employee Based on Years they have served in the company 

// SPDX-License-Identifier: MIT pragma solidity 0.8.0;

contract GiveTimeBonus{ uint public time ; string public Bonus ; //Function for time worked by Employee function GetTime( uint _yearsWorked ) public { time = _yearsWorked; } //Function for Deciding Bonus //Basic salary for worker -> 10,000 function DecideBonus() public payable returns( string memory ){ string memory percent10 = "10%"; string memory percent5 = "5%"; string memory percent8 = "8%"; if ( time > 10 ){ Bonus = percent10 ; return Bonus ; } else if ( time < 6 ){ Bonus = percent5 ; return Bonus ; } else if ( time > 6 ){ if ( time < 10 ){ Bonus = percent8 ; return Bonus ; } } } }

- Discount on Marked Price in a Shopping Complex 

// SPDX-License-Identifier: MIT pragma solidity 0.8.0;

contract DiscountedPrice{ uint public markedPrice ; string public Discount ; //Function for getting the marked price of the good function getMarkedPrice( uint _price ) public { markedPrice = _price ; } //Function for deciding the Discount function decideDiscount( ) public payable returns( string memory ){ string memory dis20 = "20%"; string memory dis10 = "10%"; string memory dis5 = "5%"; if (markedPrice > 10000) { Discount = dis20 ; return Discount ; } else if ( markedPrice < 5000 ){ Discount = dis5 ; return Discount ; } else if ( markedPrice > 5000 ){ if ( markedPrice < 10000 ){ Discount = dis10 ; return Discount ; } } } }

-Check the Triangle 

// SPDX-License-Identifier: MIT pragma solidity 0.8.0;

contract CheckTriangle{ uint public sideA ; uint public sideB ; uint public sideC ; //Function for getting the sides by User function getsideA( uint _a ) public { sideA = _a ; }

function getsideB( uint _b ) public {
    sideB = _b ;
}

function getsideC( uint _c ) public {
    sideC = _c ; 
}

function checktri() public view returns ( string memory ){
    string memory equitri = "Equilateral Triangle";
    string memory isotri = "Isoseles Triangle";
    string memory scatri = "Scalene Triangle";
    if ( sideA == sideB ){
        if ( sideB == sideC ){
            return equitri ;
        } else {
            return isotri ;
        }
    } else {
        if ( sideA == sideC ){
            return isotri ;
        } else if ( sideB == sideC ){
            return isotri ;
        } else {
            return scatri ; 
        }
    }
}

}


- Which Day of the Week it is ?

// SPDX-License-Identifier: MIT pragma solidity 0.8.0;

contract WhichDay{ uint public DayNum ; string public Day ; //Function for getting thr day number by user function getnum( uint _x) public { DayNum = _x ; } //Function for getting day function getDay() public payable returns( string memory){ string memory day1 = "Monday"; string memory day2 = "Tuesday"; string memory day3 = "Wednesday"; string memory day4 = "Thursday"; string memory day5 = "Friday"; string memory day6 = "Saturday"; string memory day7 = "Sunday"; if ( DayNum == 1 ){ Day = day1 ; return Day ; } else if ( DayNum == 2){ Day = day2 ; return Day ; } else if ( DayNum == 3 ){ Day = day3 ; return Day ; } else if ( DayNum == 4 ) { Day = day4 ; return Day ; } else if ( DayNum == 5 ) { Day = day5 ; return Day ; } else if ( DayNum == 6 ) { Day = day6 ; return Day ; } else if ( DayNum == 7 ) { Day = day7 ; return Day ; } else { Day = "Not Valid"; return Day ; } } }


All the Programs are duly  run on Remix IDE and are giving the required result. 

### Domain
<!--
And in order to tick the check box just but x inside them for example - [x] like this. Please delete options that are not relevant
-->
- [x] Solidity
#### Are you contributing under any open-source program ?
Yes, SSOC'22 ( Contributor ) 
<hr/>
Sanitya7 commented 2 years ago

@Vikash-8090-Yadav This is for Level 0 , A folder for All the If-Else Program based on Solidity for the learners. Let me know other program which we can build for If-Else in basic domain.

I will be also adding swapping and leap year program soon πŸ‘

Vikash-8090-Yadav commented 2 years ago

Add @Sanitya7 min 10 code as i am assigning u this as Intermediate level . Thank u

Sanitya7 commented 2 years ago

Hi, I have updated, check it out Thanks πŸ˜„

Vikash-8090-Yadav commented 2 years ago

min 10 code means u have to add atleast 10 code file to get intermediate label . Hope u understand :smile:

Sanitya7 commented 2 years ago

πŸ˜‚Alright, I got it wrong.

On Tue, Aug 16, 2022, 12:36 AM Vikash Yadav @.***> wrote:

min 10 code means u have to add atleast 10 code file to get intermediate label . Hope u understand πŸ˜„

β€” Reply to this email directly, view it on GitHub https://github.com/Vikash-8090-Yadav/Solidity-Pathshala/issues/39#issuecomment-1215621909, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVOREEJORT4DD3WITEX72MDVZKINFANCNFSM56ECYTTA . You are receiving this because you were assigned.Message ID: @.***>

Sanitya7 commented 2 years ago

Hi @Vikash-8090-Yadav , I have added some codes in this file πŸ‘

Vikash-8090-Yadav commented 2 years ago

@Sanitya7 ya its corrrect raise a p.r for this and made the Readme also .

Sanitya7 commented 2 years ago

πŸ‘

Vikash-8090-Yadav commented 2 years ago

if u are taking part in hackatoberfest . open this issue and ping me . @Sanitya7

Sanitya7 commented 2 years ago

Hi, Yes I am taking part in Hackatoberfest, this time I missed to contribute at my best full potential due to health issues, but now I'm back, back with a bang !

On Fri, Sep 30, 2022 at 11:54 PM Vikash Yadav @.***> wrote:

if u are taking part in hackatoberfest . open this issue and ping me . @Sanitya7 https://github.com/Sanitya7

β€” Reply to this email directly, view it on GitHub https://github.com/Vikash-8090-Yadav/Solidity-Pathshala/issues/39#issuecomment-1263884432, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVOREEMSGQVCLYLA4UK2P7TWA4V4TANCNFSM56ECYTTA . You are receiving this because you were mentioned.Message ID: @.***>

Sanitya7 commented 2 years ago

@Vikash-8090-Yadav Let us open it back and build Solidity Pathshala.

Vikash-8090-Yadav commented 2 years ago

ya sure @Sanitya7

Sanitya7 commented 2 years ago

Thanks @Vikash-8090-Yadav sir , Hackatober will be a good time to learn more

Vikash-8090-Yadav commented 2 years ago

Yup @Sanitya7 . now start working on this , sorry for the late reply :cry:

Antibodyy commented 2 years ago

@Vikash-8090-Yadav What needs to be done for this issue? I am up for the task.

Sanitya7 commented 2 years ago

Hi @Antibodyy πŸ‘‹ You may add more if-else codes in the file, We will be raising a PR, by 3rd October. Also, you may update the readme files for the same.

Sanitya7 commented 2 years ago

@Vikash-8090-Yadav You may check this, This is done almost, only readme are left, we can raise a PR for this.

Abhishek-Kumar-Sharma69 commented 2 years ago

hello @Sanitya7 , I read your above messages I can add a few more if-else block programs if required, Should I?

Vikash-8090-Yadav commented 2 years ago

@Abhishek-Kumar-Sharma69 no u can't as i am not accepting the basics codes right now.u can look into level1 folder.

Vikash-8090-Yadav commented 1 year ago

Hey @Sanitya7 are u stil working on this ?

Sanitya7 commented 1 year ago

Hi, This is done, only I have to raise PR for this. I was waiting for SWOC to raise it

Vikash-8090-Yadav commented 1 year ago

Gr8 :smile:

Sanitya7 commented 1 year ago

Hi @Vikash-8090-Yadav , I have raised a PR for the same, you may check it. Loved building this