|
Post by Azan on Sept 17, 2005 13:27:11 GMT -5
Well I was thinking about something and I figured ide try out C++, after seeing some examples I knew it would be incredibly hard. So far it doesnt have support for graphics because you need external libraries or something and either way I definitly wont be using it for graphics as it appears to be near impossible So ill stick with blitz and cobra (when it comes out) and maybe learn a little C++ on the side just for making excutables and stuff for doing mathmatical things (Anything not graphic related . Heres my simple guessing game program, I havent figured out random numbers yet as it changed depenging on the library you use (i think) #include<iostream.h> int main() { int win; int num; int g; win=0; num=50; g=1; loop: cout << "Guess a number: "; g=999; cin >> g; if (g<num) { cout << "Too low \n"; } if (g>num) { cout << "Too high \n"; } if (g==num) { cout << "You win! \n"; } if (g!=999) { goto loop; } }
And c++ is incredibly fast too, in a while loop adding 1 to a variable each loop it reached 100000 in under 6 seconds, with blitz the same thing takes 26 seconds (on my comp) WOW.
|
|
|
Post by Azan on Sept 17, 2005 18:41:25 GMT -5
Okay I figured out how to get random numbers, and how to seed them, plus I learned some more tricks to make the program better, heres a different version with comments. #include<iostream.h>
int main() { srand(time(0)); //seed the random number to the time int counter=0; //set up the game counter int number=rand()%100+1; //set up the random number int guess; //set up the variable for guess do { //start a while loop cout << "Enter a number 1-100: "; cin >> guess; //take input and assign it to guess if (guess<number) { counter++; //add 1 to counter (Note counter=counter+1 would work too) cout << "Too low you have " << 10-counter << " guesses left.\n\n"; } if (guess>number) { counter++; //add 1 to counter (Note counter=counter+1 would work too) cout << "Too high you have " << 10-counter << " guesses left.\n\n"; } if (guess==number) { counter++; //add 1 to counter (Note counter=counter+1 would work too) cout << "You win! It took you " << counter << " guesses.\n\n"; system("PAUSE"); //Blitz equivalent is WaitKey() break; //End } if (counter>=10) { cout << "Sorry, you lost.\n"; system("PAUSE"); //Blitz equivalent is WaitKey() break; //End } } while (1==1); //loop forever }
Oh yeah and guess what, it has lists that behave just like they did in python w00t, in many ways they are better than the ones in python. BTW does anyone want to know where I got my IDE? because I can track down the link as its one of the best C++ IDEs out there.
|
|
|
Post by Qecbum on Sept 18, 2005 11:12:16 GMT -5
this is wrong im sorry for this but dont take any more responciblity for his actoins
|
|