Page 2 of 3
Posted: Wed Dec 12, 2007 10:24 am
by sirtom93
My friend and i were searching dreamcast homebrew games when we came accros this. That code does actualy work. I compile and it plays through fine..... If you want i could upload the .exe
Im 14 years of age. I have 2 years to do whatever i want so why not do c++,my cousin is a master at it and has a computing technology degree. He gave me the books.
Posted: Wed Dec 12, 2007 10:39 am
by Tvspelsfreak
Something must've gone wrong when you copied the code to your post then. Even if that did for some reason pass compilation it wouldn't work as you'd want.
Posted: Wed Dec 12, 2007 4:32 pm
by sirtom93
Ok,here it is again.
Code: Select all
// higher lower game by sirtom93.
#include <time>
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int guess;
int answer= rand() %10+1;
cout<< "welcome to the higher or lower game, by Sirtom93";
cout<< "\n";
cout<< "Please enter a number between 1 and 10: ";
cin>> guess;
cout<<"\n\n";
while ((guess>answer)||(guess<answer>answer){
cout <<"the number is to big,please try again";
cin >> guess;
}
if (guess<answer){
cout <<"the number is to small,please try again";
cin>> guess;
}
}
if (guess=answer);
cout<<"well done,you guessed right!";
cout<< "\n\n\n";
system ("PAUSE");
return (0);
}
Posted: Sat Dec 15, 2007 3:14 pm
by sirtom93
Code: Select all
//Newrounds quiz by sirtom93.
#include <iostream>
#include <string>
using namespace std;
int main (){
string creator;
int score=0;
cout<<"Hello and welcome to the newgrounds quiz v1.0.\nYou can testyour knowledge on how well you know newgrounds! ";
cout<<"\n";
//Questions start here.
cout<<"question one: who is the creator of newgrounds";
cin>>creator;
//if and else loops statements.
if (creator=="TomFulp" ||creator=="tomFulp" || creator=="Tomfulp"){
cout<<"that is correct\n";
score+1;
}
else{
cout<<"that is incorrect \n\n";
cout<<"Your final score is"<<score"\n";
}
system ("PAUSE");
return (0);
}
The start of my Newgrounds quiz game.
Posted: Sat Dec 15, 2007 7:39 pm
by Arce
That's kewl--It's good to see you applying your knowledge and making something that's not right out of the book.
I haven't actually had time to look through the code--But does it work this far? If so, great job.
One thing that I did notice as I was scrolling through...Your braces are indented off. That's fine, it takes a while to learn good style, but try your best to keep it all lined up. See, this:
Code: Select all
if (creator=="TomFulp" ||creator=="tomFulp" || creator=="Tomfulp"){
cout<<"that is correct\n";
score+1;
}
else{
should be
Code: Select all
if (creator=="TomFulp" ||creator=="tomFulp" || creator=="Tomfulp"){
cout<<"that is correct\n";
score+1;
}
else{
so that the end brace is lined up with the if statement.
Again, it's not an error or anything, but it prevents confusion and is good practice. Our Perl programmer for our game right now has complete shit style too, don't feel too bad. =P
Posted: Sun Dec 16, 2007 12:37 am
by Falco Girgis
You should tolower() your string input so that you won't have to check all cases. It's in cstring.h.
Posted: Sun Dec 16, 2007 6:26 am
by sirtom93
Ok thanks guys.
Posted: Sun Dec 16, 2007 11:12 am
by sirtom93
Im thinking of having a loop that goes back to the start if the user so desires. something like...
Code: Select all
char y/n = y
while (y/n ="n"){
// code
cout<<"do you wish to continue: ";
cin>> y/n;
}
is that the best way of doing so?
Posted: Sun Dec 16, 2007 4:33 pm
by Falco Girgis
Your while loop is still screwed up. You're setting it equal to "n," not testing for equality.
Use ==.
Posted: Mon Dec 17, 2007 10:08 am
by sirtom93
GyroVorbis wrote:Your while loop is still screwed up. You're setting it equal to "n," not testing for equality.
Use ==.
ahh i see. So == in a way compares the two and = makes it the same.
Posted: Mon Dec 17, 2007 10:53 am
by Tvspelsfreak
Yes. And while on the subject of that code snippet you can't have / in a variable name, that's division. You also can't compare strings with == (at least not C strings) like you're trying to. You can compare chars like that but "n" in this case is a null terminated string. To treat it as a char you do 'n' instead. Same applies to when you initialize your variable.
Posted: Mon Dec 17, 2007 12:59 pm
by sirtom93
Tvspelsfreak wrote:Yes. And while on the subject of that code snippet you can't have / in a variable name, that's division. You also can't compare strings with == (at least not C strings) like you're trying to. You can compare chars like that but "n" in this case is a null terminated string. To treat it as a char you do 'n' instead. Same applies to when you initialize your variable.
Got you. You may not see me round here that much as im going to to all out learning c++ over christmas and the internet distracts me.
Posted: Sat Feb 02, 2008 3:45 pm
by Kleithap
Just read all these post, and NO OFFENSE but: ROFL.
That's all, thank you very much.
Posted: Fri Feb 15, 2008 1:25 am
by Ingulit
Kleithap wrote:Just read all these post, and NO OFFENSE but: ROFL.
That's all, thank you very much.
^^^^^^^^^^^
If you're into C/C++ game programming, I'd recommend Sam's Teach Yourself C++ in 24 Hours as a C++ primer, and then Game Programming All-in-One, Third Edition to get you used to game code (and get you out of the console).
DISCLAIMER: I'm not trying to be rude with the following comment, so just hear me out.
The first game you posted, the one that took you a month? For most programmers who have a true chance in the field, such a program would've been their day 2 or 3 project, if even that late. You might want to reconsider this, for even with a ton of dedication, true game programming will require you to learn vast amounts of new things and to be able to apply them in a very short amount of time. I have no advice for how to do this, but you're going to have to learn faster if you are truly interested.
DISCLAIMER: I was not trying to be rude with the previous comment, so just heed what I said and consider it.
Posted: Fri Feb 15, 2008 2:34 pm
by MarauderIIC
Necromancy spooooooooooky.....