🔒 Closed Numerical Guessing Game

Status
Not open for further replies.

babita14

Fanatic
Nag aaral ako ng c++, about a month na. Hirap pala neto haha pero enjoyable.
So, share ko lang yung guessing game ko in c++.

Code:
// guranume.cpp: A numerical game against the computer
#include <iostream>
#include <ctime> // Prototype of time()
#include <cstdlib> // Prototype of srand() and rand()

using namespace std;

int main ()
{
    unsigned sec = time(0); // Get the time in seconds

    srand(sec); // Seeds the random number generator

    cout << "\n\t****** Numerical Guessing Game ******"
         << "\n\tRules;\n"
         << "\t\t  I have a number between 1 to 15 in mind,\n"
         << "\t\t  You have three chances to guess correctly!" << endl;
   
    char play = 'r'; // be able to replay <r> or quit <q>
    int i = 1;

    while (play == 'r')
    {
        int ranNum = rand() % 15 + 1; // random number between 1 to 15

        bool foundAnswer = false;
        int numTry = 1, answer;
        while (!foundAnswer && numTry <= 3)
        {
            cin.sync();     // clear input buffer for  
            cin.clear();
            cout << "\n\t\t  Trial " << numTry++ << ". : ";
            cin >> answer;
            if ( answer == ranNum)  foundAnswer = true;
            else if (answer < ranNum) cout << "\t\t  Too small!" << endl;
            else cout << "\t\t  Too big!" << endl;
           
        }

        if (!foundAnswer)
        {
            cout << "\n\t\t  I win! You lose! ha ha ha"
                 << "\n\t\t  The number in question is: " << ranNum << endl;
        }
        else cout << "\t\t  Argh you Win!" << endl;



        cout << "\n\t\t  Play again?"
             << "\n\t\t  Replay -> <r>\t\tQuit -> <q> : ";
       
        cin >> play;
    }
    return 0;
}
 
Ganun siguro pag na interest at walang magawa. Wala kasing pressure pag inanaaral nalng, diko to magugustuhan kung studyante ako
 
Hindi naman ako magaling, antagal ko yang inupuan. Almost a month haha

Trust the process lang. Matoto para sa ikabubuti ng sarili mo, wag kang matoto para sa ikalalamang mo sa iba. Don't campare yourself with others. Iba ka, iba ako at higit sa lahat, iba sila.
 
Sige lang lods.
may bug pala yan. di ko nalaman ko pano e debug. Balik trabaho na kasi. busy na.

Bug:
Nagiging infinite loop
Diba integer lang dapat answer. kunwari nagkamali ka ng na input para sa answer at na input mo ay letter(s) nagiging infinite loop.
 
I found a warning in it pero hindi naman ata bug kasi yung hinihingi mo number hindi letters. Yes I tried it at talagang hindi na humihinto. Still new sa c++ rin eh.

Screenshot 2021-01-24 213058.webp
 
nakaka enjoy po kapag hindi limited yung oras mo. like hindi mo need magpasa on time. kapag nappressure ka po kasi, ang hirap talaga matuto
 
[XX='crxz619, c: 885293, m: 948334'][/XX]Tama. Pero trust the process lang mga paps and time management. Know your Priorities ika nga😊
 
Status
Not open for further replies.

About this Thread

  • 11
    Replies
  • 667
    Views
  • 6
    Participants
Last reply from:
I am nobody

Online now

Members online
1,007
Guests online
854
Total visitors
1,861

Forum statistics

Threads
2,276,222
Posts
28,968,417
Members
1,231,173
Latest member
JJJJMMMM
Back
Top