What's new

Closed Sino merong code (Guessing game)

Status
Not open for further replies.

Falln

Forum Veteran
Joined
Mar 16, 2016
Posts
1,883
Reaction
280
Points
742
sino po pwede makatulong sakin dito sa activity namin. Nahihirapan kase ako. Baka meron sainyo nagawa na ito or pwede nyo naman ako bigyan ng code pa comment nalang po, bukas na kase deadline. Thank you malaking tulong po sakin kung matulungan nyo ako dito.
 

Attachments

ganito beginner tutorial sa pdf na binasa ko ng nakaraan, bigyan na lang kita pseudocode tutal bukas pa naman yan

// number guessing
int toGuess;
// holder
int yourGuess;

toGuess = (get random number)
do {
line1:
// print your statement and get user result
line 2:
// check condition if user input match, print statement
} while (yourGuess != toGuess) // will execute once, whether true or false
 
ganito beginner tutorial sa pdf na binasa ko ng nakaraan, bigyan na lang kita pseudocode tutal bukas pa naman yan

// number guessing
int toGuess;
// holder
int yourGuess;

toGuess = (get random number)
do {
line1:
// print your statement and get user result
line 2:
// check condition if user input match, print statement
} while (yourGuess != toGuess) // will execute once, whether true or false
may full code ka sir?
 
Nak ng tokwa! hindi ako ganto nung college ako. Naghanap pa ng fullcode! maghanap ka na ng iba mong course kapatid. Baka hindi para sayo ang IT/CS.

Java:
/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.util.Scanner;

public class Main
{
  public static void main (String[]args)
  {

    int numberToGuess = 17; //make it dynamic using random method.
    int userGuess = 0, countOfGuessing = 0, life = 4;

    Scanner input = new Scanner (System.in);

    System.out.println ("Input you guess :");
    userGuess = input.nextInt ();

    while (userGuess != numberToGuess && life > 0) {

        life -= 1;
        countOfGuessing += 1;

        clearScreen ();

        if (userGuess > numberToGuess) {

            System.out.println ("Lower guess please :");
        }
        else if (userGuess < numberToGuess)
        {

            System.out.println ("Higher guess please :");
        }

       userGuess = input.nextInt ();
       System.out.println ("\n");
    }

    if(life <= 0) {
       
        System.out.println ("Game over! You can only guess 5x.");
    }
    else {
       
        System.out.println ("Congratulations!");

        System.out.println ("---------------");

        System.out.println ("Number Of Attempt : " + countOfGuessing);

        System.out.println ("---------------");
    }
}

    public static void clearScreen () {

        System.out.print ("\033[H\033[2J");
        System.out.flush ();
    }
}
 
Last edited:
eto ts, pagaralan mo
Java:
import java.util.Random;
import java.util.Scanner;
public class GuessingGame {
    //pre defined method for inputs
    static Scanner sc = new Scanner(System.in);
   
    public static void main(String[] args) {
        Random rand = new Random();
        int range_of_numbers = 20;
        int guess_the_number = rand.nextInt(range_of_numbers)+1; // 20 is the current limit of numbers can be randomize.
                                                    //Add 1 for every randomize number to not to get a 0.
        int guessed_number = 0;
        int number_of_tries = 0;
        int limit_of_tries = 10; // Change it if you want
       
        System.out.println("Guess the Number from 1 to "+range_of_numbers);
       
        //Condition: The loop will go on if the guessed number is not equal to the secret number,
        //and the number of tries is less than the limit tries.
        while(guessed_number != guess_the_number && number_of_tries < limit_of_tries) {
            //Get the input from the user
            System.out.println("Guess the number: ");
           
            guessed_number = sc.nextInt();
            // number of tries will increment every number that the user guessed.
            ++number_of_tries;
           
            // if the guessed number is higher than secret number
            if(guessed_number < guess_the_number)
                System.out.println("Higher Please");
           
            // if the guessed number is lower than the secret number
            else if(guessed_number > guess_the_number)
                System.out.println("Lower Please");
           
            // the user guessed the corrent secret number
            else {
                System.out.println("Congratulations! You Have guessed the correct number");
                break; //End of the loop
            }
        }
        System.out.println("Number of Tries: "+number_of_tries);
        System.out.println("Thank you for guessing!");
    } //end of main
} //end of class
 
Nak ng tokwa! hindi ako ganto nung college ako. Naghanap pa ng fullcode! maghanap ka na ng iba mong course kapatid. Baka hindi para sayo ang IT/CS.

Java:
/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.util.Scanner;

public class Main
{
  public static void main (String[]args)
  {

    int numberToGuess = 17; //make it dynamic using random method.
    int userGuess = 0, countOfGuessing = 0, life = 4;

    Scanner input = new Scanner (System.in);

    System.out.println ("Input you guess :");
    userGuess = input.nextInt ();

    while (userGuess != numberToGuess && life > 0) {

        life -= 1;
        countOfGuessing += 1;

        clearScreen ();

        if (userGuess > numberToGuess) {

            System.out.println ("Lower guess please :");
        }
        else if (userGuess < numberToGuess)
        {

            System.out.println ("Higher guess please :");
        }

       userGuess = input.nextInt ();
       System.out.println ("\n");
    }

    if(life <= 0) {
      
        System.out.println ("Game over! You can only guess 5x.");
    }
    else {
      
        System.out.println ("Congratulations!");

        System.out.println ("---------------");

        System.out.println ("Number Of Attempt : " + countOfGuessing);

        System.out.println ("---------------");
    }
}

    public static void clearScreen () {

        System.out.print ("\033[H\033[2J");
        System.out.flush ();
    }
}
Thank you sir, sorry **** ako sa programming eh
 
Thank you sir, sorry **** ako sa programming eh


No offense yan kapatid. This is supposed to be your seat work and I'm sure you have tackled it already before your prof gave it to you as your activity. Programming is difficult but doable when studying it with much effort and time.
 
No offense yan kapatid. This is supposed to be your seat work and I'm sure you have tackled it already before your prof gave it to you as your activity. Programming is difficult but doable when studying it with much effort and time.
tama si boss dpat di e spoon feed. kayo din ang mahihirapan pag nag work na kayo pag ganito mindset mo ts. di ka tatagal sa field nato.. di lang mang hinge ng full code.. e comprehend din ang code structure at ang proper coding style. yan ang tips ko sayo ts. HONESTLY nasa easy/basic part pato ng controlled structure lessthan 100 lines lng to. sana e comprehend mo ang code para sa next seatwork nyo alam mona paano ang structuring ng algo nito. Good Luck ts.
 
tama si boss dpat di e spoon feed. kayo din ang mahihirapan pag nag work na kayo pag ganito mindset mo ts. di ka tatagal sa field nato.. di lang mang hinge ng full code.. e comprehend din ang code structure at ang proper coding style. yan ang tips ko sayo ts. HONESTLY nasa easy/basic part pato ng controlled structure lessthan 100 lines lng to. sana e comprehend mo ang code para sa next seatwork nyo alam mona paano ang structuring ng algo nito. Good Luck ts.
Correct! ang hirap sa mga ibang member dito, nanghihingi na, sasama pa loob pag napuna ang mali. ang simpleng problem lang yan, nung college ako, kahit papel nagko-codes ako. paano na lang kung aabot ng libong lines of codes ang ipagawa sa kanila? e di iyak sila. At saka grabe, hindi ganyan ang mga seatwork namin nung college ako. hahaha! grabe yan, pang high school yata yan e. Second year ako nung pinag codes na kami ng cpu scheduling e. nataon pa sakin yung rr at sjf hinayupak na yan!
 
Correct! ang hirap sa mga ibang member dito, nanghihingi na, sasama pa loob pag napuna ang mali. ang simpleng problem lang yan, nung college ako, kahit papel nagko-codes ako. paano na lang kung aabot ng libong lines of codes ang ipagawa sa kanila? e di iyak sila. At saka grabe, hindi ganyan ang mga seatwork namin nung college ako. hahaha! grabe yan, pang high school yata yan e. Second year ako nung pinag codes na kami ng cpu scheduling e. nataon pa sakin yung rr at sjf hinayupak na yan!
hahahaha.. remember ko din yang job scheduling sa task sa CPU. tpos need namin e explain line by line with illustration including ung computation ng memory allocation demonyo talaga tingin ko sa teacher namin nun kasi after nun isa2 kaming tinawag sa table nya then parang pina defense sa amin kung bakit ganito ganyan ang manyayari.. tpos sa PL pa namin na klase nun pinagawa kami ng sarili naming Programming language na may sariling Progamming Padigrims, Semantics, Lexical, compiler at etc pa. Isang sem din kaming halos dimaka kain nun kasi ung mga tutorial sa Stack nun eh dika pwede pa spoonfeed pahelp sa debugging lng ang ginagawa ng mga master dun dati. tpos malaman mo nlng na EZ gain nlng ung ibang mga Source Code ngaun. Tpos mas madali nlng matuto mag code ngaun dali sa mga INDIAN friends nating sa YøùTùbé. tsk. Computer Science pa More.
 
hahahaha.. remember ko din yang job scheduling sa task sa CPU. tpos need namin e explain line by line with illustration including ung computation ng memory allocation demonyo talaga tingin ko sa teacher namin nun kasi after nun isa2 kaming tinawag sa table nya then parang pina defense sa amin kung bakit ganito ganyan ang manyayari.. tpos sa PL pa namin na klase nun pinagawa kami ng sarili naming Programming language na may sariling Progamming Padigrims, Semantics, Lexical, compiler at etc pa. Isang sem din kaming halos dimaka kain nun kasi ung mga tutorial sa Stack nun eh dika pwede pa spoonfeed pahelp sa debugging lng ang ginagawa ng mga master dun dati. tpos malaman mo nlng na EZ gain nlng ung ibang mga Source Code ngaun. Tpos mas madali nlng matuto mag code ngaun dali sa mga INDIAN friends nating sa YôùTùbé. tsk. Computer Science pa More.
Nako, same ang mga hirap na pinag daanan natin paps. grabe din mga prof ko noon. every activity kaylangan alam mong ikwento ang code mo. tapos isa pa yang assembly language na yan. hinayupak na yan. kahirap talaga kasi memory allocation sya. alam mo dapat kung saan mo iregister yung data mo. pero dun nahasa ang knowledge ko talaga sa logic at analysis.
 
Status
Not open for further replies.

Similar threads

Back
Top