Create a Guess Game

This is the place for ALL of the user submitted challenges. If you create a little challenge/mission/riddle/whatever, post it here.
Forum rules
Do not post missions that you did NOT create without proper citing.

Re: Create a Guess Game

Post by Assassian360 on Thu Aug 15, 2013 10:48 pm
([msg=76866]see Re: Create a Guess Game[/msg])

-Ninjex- wrote:@assassian360, I am getting compilation errors here:

Code: Select all
>> g++ guess.cpp
guess.cpp: In function ‘int main()’:
guess.cpp:8:24: error: ‘srand’ was not declared in this scope
guess.cpp:12:28: error: ‘rand’ was not declared in this scope
guess.cpp:24:41: error: ‘abs’ was not declared in this scope


That suggests that your compiler doesn't have the standard definitions for math.h and time.h. Those are defined inside of those core headers. I'll try compiling both in g++ before I put updated versions up.
Assassian360
Poster
Poster
 
Posts: 135
Joined: Sat Jun 26, 2010 1:37 am
Blog: View Blog (0)


Re: Create a Guess Game

Post by -Ninjex- on Thu Aug 15, 2013 11:05 pm
([msg=76869]see Re: Create a Guess Game[/msg])

Assassian360 wrote:
-Ninjex- wrote:@assassian360, I am getting compilation errors here:

Code: Select all
>> g++ guess.cpp
guess.cpp: In function ‘int main()’:
guess.cpp:8:24: error: ‘srand’ was not declared in this scope
guess.cpp:12:28: error: ‘rand’ was not declared in this scope
guess.cpp:24:41: error: ‘abs’ was not declared in this scope


That suggests that your compiler doesn't have the standard definitions for math.h and time.h. Those are defined inside of those core headers. I'll try compiling both in g++ before I put updated versions up.


I tried g++ and gcc, here is the version for both:

Code: Select all
ninjex@kali:~ >> gcc --version
gcc (Debian 4.7.2-5) 4.7.2


Thanks for your response.
I had a look at: http://www.cplusplus.com/reference/cmath/
The above definitions do not look like they are linked to the c++ math header, they are separate.
image
For those that know
K: 0x2CD8D4F9
User avatar
-Ninjex-
Moderator
Moderator
 
Posts: 1691
Joined: Sun Sep 02, 2012 8:02 pm
Blog: View Blog (0)


Re: Create a Guess Game

Post by Assassian360 on Thu Aug 15, 2013 11:24 pm
([msg=76874]see Re: Create a Guess Game[/msg])

Here's a fixed version. It should compile in g++ now.

Code: Select all
#include <iostream>
#include <time.h>
#include <algorithm>
using namespace std;

int main(int argc, char* argv[]) {
    srand(time(NULL));
   int difficulty;
   cout << "Enter difficulty: ";
   cin >> difficulty;
   int solution = rand() % (15 + (difficulty-1) * 5) + 1;
   int guessRemaining = 5 + (int)(difficulty * 0.75);
   cout << "Guess numbers between 1 and " << (15 + (difficulty-1) * 5) << endl;
   while(guessRemaining) {
      cout << "You have " << guessRemaining
         << " guesses remaining.\n";
      cout << "Enter your guess: ";
      int guess;
      cin >> guess;
      if(guess == solution) {
         cout << "Congratulations, that was correct!\n";
         break;
      } else if(abs(guess - solution) < 2 + (difficulty-1)) {
         cout << "HOT! You are really close!\n";
      } else if(abs(guess - solution) < 4 + 2 * (difficulty-1)) {
         cout << "Kind of warm, but a bit far off.\n";
      } else {
         cout << "Kind of cold, try to find something warmer.\n";
      }
      guessRemaining--;
   }

   if(!guessRemaining)
      cout << "Sorry, you used up all your attempts.\n";
   cin >> difficulty;
   return 0;
}
Last edited by Assassian360 on Fri Aug 16, 2013 12:07 am, edited 1 time in total.
Assassian360
Poster
Poster
 
Posts: 135
Joined: Sat Jun 26, 2010 1:37 am
Blog: View Blog (0)


Re: Create a Guess Game

Post by -Ninjex- on Thu Aug 15, 2013 11:30 pm
([msg=76875]see Re: Create a Guess Game[/msg])

@assassian360, the code is working, however your difficulties start off a bit wrong. Level 1 should be a number 1-15, you have it as 1-20. Other than this, great work. +50 until the small fix is made.
image
For those that know
K: 0x2CD8D4F9
User avatar
-Ninjex-
Moderator
Moderator
 
Posts: 1691
Joined: Sun Sep 02, 2012 8:02 pm
Blog: View Blog (0)


Re: Create a Guess Game

Post by Assassian360 on Fri Aug 16, 2013 12:08 am
([msg=76876]see Re: Create a Guess Game[/msg])

-Ninjex- wrote:@assassian360, the code is working, however your difficulties start off a bit wrong. Level 1 should be a number 1-15, you have it as 1-20. Other than this, great work. +50 until the small fix is made.

Fixed it.
Assassian360
Poster
Poster
 
Posts: 135
Joined: Sat Jun 26, 2010 1:37 am
Blog: View Blog (0)


Re: Create a Guess Game

Post by -Ninjex- on Fri Aug 16, 2013 12:16 am
([msg=76877]see Re: Create a Guess Game[/msg])

@assassian360, +25
image
For those that know
K: 0x2CD8D4F9
User avatar
-Ninjex-
Moderator
Moderator
 
Posts: 1691
Joined: Sun Sep 02, 2012 8:02 pm
Blog: View Blog (0)


Re: Create a Guess Game

Post by F6Zman on Mon Aug 26, 2013 5:20 pm
([msg=77041]see Re: Create a Guess Game[/msg])

My code in HTML/Javascript:

Code: Select all
<html>
<head>

<script type="text/javascript" language="javascript">

var randnumb = (Math.floor (Math.random()*16));
var numGuesses = 2;


function gameTime()
{
var guess = document.getElementById("guess").value;

var status = document.getElementById("status");

if(guess == randnumb)
{
alert("You Win!")
}

else if(guess == randnumb + 1)
{
alert("hot")
numGuesses--;
}
else if(guess == randnumb + 2)
{
alert("hot")
numGuesses--;
}
else if(guess == randnumb - 1)
{
alert("hot")
numGuesses--;
}
else if(guess == randnumb - 2)
{
alert("hot")
numGuesses--;
}
else if(guess == randnumb + 3)
{
alert("warm")
numGuesses--;
}
else if(guess == randnumb + 4)
{
alert("warm")
numGuesses--;
}
else if(guess == randnumb - 3)
{
alert("warm")
numGuesses--;
}
else if(guess == randnumb - 4)
{
alert("warm")
numGuesses--;
}
else
{
alert("cold")
numGuesses--;
}

if(numGuesses == 0)
{
alert("You are out of Guesses!, This game is now void!")

}
else
""

}
</script>
</head>
<body>
<center>
<label for = "guess"> Your Guess: </label>
<input type = "text" id = "guess" value = "" />
<input type = "button" onclick = "gameTime()" value = "Submit" />
<center/>

</body>
</html>
F6Zman
New User
New User
 
Posts: 11
Joined: Tue Aug 13, 2013 9:33 am
Blog: View Blog (0)


Re: Create a Guess Game

Post by -Ninjex- on Mon Aug 26, 2013 10:10 pm
([msg=77050]see Re: Create a Guess Game[/msg])

@F6Zman

The code you gave for me isn't working for my apache sever, nor is it working on www.jsfiddle.net
Let me know if I should have something set up on my end other than just using your code.
image
For those that know
K: 0x2CD8D4F9
User avatar
-Ninjex-
Moderator
Moderator
 
Posts: 1691
Joined: Sun Sep 02, 2012 8:02 pm
Blog: View Blog (0)


Re: Create a Guess Game

Post by F6Zman on Tue Aug 27, 2013 1:06 am
([msg=77054]see Re: Create a Guess Game[/msg])

-Ninjex- wrote:@F6Zman

The code you gave for me isn't working for my apache sever, nor is it working on http://www.jsfiddle.net
Let me know if I should have something set up on my end other than just using your code.


Try it here: http://www.w3schools.com/html/tryit.asp ... html_intro
F6Zman
New User
New User
 
Posts: 11
Joined: Tue Aug 13, 2013 9:33 am
Blog: View Blog (0)


Re: Create a Guess Game

Post by pretentious on Tue Aug 27, 2013 1:14 am
([msg=77056]see Re: Create a Guess Game[/msg])

F6Zman wrote:My code in HTML/Javascript:

Code: Select all
...
var numGuesses = 2;
...

Wow haha, now that's truelly a guessing game
Goatboy wrote:Oh, that's simple. All you need to do is dedicate many years of your life to studying security.

IF you feel like exchanging ASCII arrays, let me know ;)
Can you say brainwashing It's a non stop disco
User avatar
pretentious
Addict
Addict
 
Posts: 1203
Joined: Wed Mar 03, 2010 12:48 am
Blog: View Blog (0)


PreviousNext

Return to User Submitted

Who is online

Users browsing this forum: No registered users and 0 guests