Sorry man I don't know java yet. Sticking with c++ for now. So if you don't want to see it skip to the next post. But just some simple C++, this is what i would do:
- Code: Select all
#include <iostream>
#include <string>
using namespace std;
int main()
{
int guess = 0, magicNum = 79, cdown = 6;
string name;
while((guess != 79) || (cdown > 0))
{
cout << "You have " << cdown << " tries." << "Pick a number (1 through 200): ";
cin >> guess;
if(guess > magicNum)
{
cout << "Too high.\n";
--cdown;
}
else if(guess < magicNum)
{
cout << "Too low.\n";
--cdown;
}
else
{
cout << "CONGRATULATION, YOU WON A PRIZE!!!!\n";;
}
}
if(!cdown)
{
cout << "Sorry, you're out of tries.\n";
}
return 0;
}
Giving longer time, I would have the magicNum variable random instead of static, and also verify that it's a legit number. Open for correction. Shit, we need more stuff like this to keep skill up and keep shit competitive.
Edit in response to:
Post a little brain teaser (not unlike Project Euler in scope) and just reply with possible solutions in any language
Project Euler. Lol, Most of my down time at work is spent on there so it looks like I'm working on something.