Messages - alivingspirit [ switch to compact view ]

Pages: prev1 ... 20 21 22 23 24 [25]
121
Coding Snacks / My first program.
« on: July 01, 2008, 04:33 PM »
Hi everyone. So basically, I just started learning to program this Sunday in c++ (sorry Tinjaw that Python was not my 1st choice, but it is on my list to learn eventually).  :D So after messing around for a few days I came up with my first program. Its a game where you try and guess the number that the computer comes up with at random. I actually find it a little bit addicting. I'll keep adding to it as my skills progress. Ill post more updates if you guys like it. This might not belong in the coding snacks section and if not I'm sorry. I guess I'm just exited that I finally got around to learning this stuff.
OK, The program is attached. or get it here: http://www.mediafire.com/?e0nd9gemgcc
Here is the source code:
#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

int num();
int game ();
int x;
int y;
int a;
int answer;
int tries;
int gp = 0;
int gw = 0;

int main() {

    tries = 6;
    a = 1;
    srand((unsigned)time(NULL));
    answer = num();
    cout<<"Games played: "<< gp << "       Games Won: "<< gw <<"\n\n";
    cout<<"Guess a number 1 through 100: ";
    game();

}

int game() {
        do {
        cin>> y;
        tries--;
        if ( y > 100  ||  y < 1 ) {
            cout<<"Sorry that is not a valid entry\n";
            cout<<"Guess another number: "; }

        else if ( y < answer ) {
            cout<<"That number is too LOW. Try again.\n";
            if ( tries != 0 ) {
            cout<<"You have " << tries <<" tries left.\n"; }
            else {
            cout<<"You are out of tries.\n"; } }

        else if ( y > answer ) {
            cout<<"That number is too HIGH. Try again.\n";
            if ( tries != 0 ) {
            cout<<"You have " << tries <<" tries left.\n"; }
            else {
            cout<<"You are out of tries.\n"; } }

        else {
            cout<<"You got it!";
            cout<<"\n\n\n";
            gp++;
            gw++;

            main(); }

        if (tries == 0) {
            cout<<"\nGame Over! Play again.\n\n\n";
            gp++;
            main();
            }
    }
while (1); }


int num() {
   return x = (rand() % 99) + 1 ; }


As you can see it is still a work in progress. There is one major glitch that I don't know how to correct yet and that is if you type in anything other than a number it flips out. I will fix it as soon as I learn how. For now have fun.
I appreciate any comments on how to improve or add to the game. I hope to be able to code more usefull programs in the future.
:Thmbsup:

122
General Software Discussion / Re: Skip Detector
« on: June 22, 2008, 01:32 PM »
Thanks Lashiec, EAC does exactly what I need. It did require an awful lot of setup though. 

123
General Software Discussion / Skip Detector
« on: June 22, 2008, 12:38 PM »
Is there a program that will check a CD for song skips or errors in data files? (This may be the last time I ever burn a CD again.)  :mad:

124
a plugin that makes it easy to search/browse and install plugins

Pages: prev1 ... 20 21 22 23 24 [25]
Go to full version