AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   C++ Gaben test [Done] (https://forums.alliedmods.net/showthread.php?t=51272)

Da_sk8rboy 02-14-2007 16:19

C++ Gaben test [Done]
 
2 Attachment(s)
Thank's for the help guys ;)
The .zip files are all up-to-date (The source code also) ;)

Thanks to
:
  • Xanimos
  • Zenith77
  • LittleDude
The .zip files contain:
  • The Gaben test Source.zip file. (Source code for program)
  • The Gaben test.exe (The program)
Thank's again for the help ;)

(I would appreciate it if someone could explain to me the loop Zenth77 was talking about. I'm fairly new to C++ so be nice.) ;)

lunarwolfx 02-14-2007 16:36

Re: C++ help
 
well it's working correctly, it's just that the console shutdowns whenever the program ends.

I forgot what you have to add at the end of the function to make it ask you to press a key to continue, but I think it is getchar();

Ephraim 02-14-2007 16:36

Re: C++ help
 
if(killedByGaben)
cout << "\As you

\A ??

;)
Without this it works for me.

Ciao Ephraim

Da_sk8rboy 02-14-2007 16:51

Re: C++ help
 
Ahh I forgot the "\n"
But now if you press 0 it exits.. Which its not suppose to do.. Its suppose to display:
Code:

You take the shining Pickles,
          but you have failed the second test!
          You've proven you're GREED. . .
          Game 0ver. . .

Also if you keep pressing 0 @ the very end if you comlete it its suppose to say:
Code:

                          Congratualations, you
                          have passed all three tests!
                          You exit the chamber &
                          confront Gaben.
                          He tries to eat you whole
                          but you move on.
                          With one swing of your trout it is over.
                          You and your computer live happily ever after.
                          The 3nd. . .

But it doesnt. anytime 0 is pressed the program is exited..

Zenith77 02-14-2007 20:57

Re: C++ help
 
You need to do a while loop, something like:

Code:

bool quit;
while (!quit)
{
    if (inpute == 0)
        quit = true;
}

system("PAUSE"); // This is optional :-).

Put the main program code in there :-). It's exiting like that because once it's done displaying everything (almost immediatly), it then has no more code to execute, thus ending the program.

Da_sk8rboy 02-14-2007 21:19

Re: C++ help
 
Yeah, Well i got most of it done (thanks Xanimos :p) But im still having trouble with one part. All the ones work besides the first test when you press 1 in the first test.... It exits the program.. But if you hit 0 then 1 it works on the second & third test.. Here my new code:

Code:

//*Britt Jamerson - Gaben, Take or go test! - v1.0*
#include <iostream>
using namespace std; 
int main( void )
{
    cout << "\n A code by Britt Jamerson aka Da_sk8rboy--no0bsawce!"
            "\n+-----------------------------------------------------------------------+"
            "\n| Welcome to the Gaben take or go test!.                                |"
            "\n| Gaben has stolen your computer and it is up to you to get it back.    | "
            "\n| Gaben say's you must pass the Gaben take or go test! ! !              |"
            "\n+-----------------------------------------------------------------------+";
    bool clamsTaken, picklesTaken, killedByGaben;
    cout << "\n\nYou enter the first chamber."
            "\nIt's full of purple clam's, "
            "you cannot believe."
            "\nDo you take the clam's (1=Yes, 0=No)? ";
    cin >> clamsTaken;
   
    if(clamsTaken)
    {
        cout << "\nYou keep the clams, but you have failed the first test."
                "\nGame 0ver. . .\n\n";
    }
    else
    {
        cout << "Congratulations, "
                "you have passed the first test!"
                "\n\nYou enter the second chamber."
                " It is full of shining Pickles! ! !"
                "\nDo you take the shining pickles"
                "(1=Yes, 0=No)?";

        cin >> picklesTaken;

        if(picklesTaken)
        {
            cout << "You take the Shining Pickles, "
                    "but you have failed the second test!"
                    "\nYou've proven you're GREED. . ."
                    "\nGame 0ver. . .\n\n";
        }
        else
        {
            cout << "Congratulations, you have passed the Second test!"
                    "\n\n You enter the Third chamber. "
                    "\n A no0b is being attacked by a MiniGaben!"
                    "\nDo you ignore the no0b & move on (1=Yes, 0=No)?";

            cin >> killedByGaben;
            if(killedByGaben)
            {
                cout << "\nAs you sneak by, the MiniGaben turn's his attenetion "
                        "to you."
                        "\nHe grabs you & eat's you whole with one bite. . ."
                        "You are now dead."
                        "\nGame 0ver. . .\n\n";
            }
            else
            {
                cout << "Congratualations, you"
                        " have passed all three tests!\n\n"
                        "You exit the chamber & "
                        "confront Gaben.\n\n"
                        "He tries to eat you whole "
                        "but you move on.\n"
                        "With one swing of your trout it is over.\n\n"
                        "You and your computer live happily ever after.\n\n"
                        "The End. . .\n\n";
            }
        }       
        system("PAUSE");
    }
    return 0;
}

If you want i can give you the update .exe To see what i mean?

LittleDude 02-14-2007 21:59

Re: C++ help
 
you gotta return 0 back to the calling program so it knows to end.

Code:

//*Britt Jamerson - Gaben, Take or go test! - v1.0*
#include <iostream>
using namespace std; 
int main( void )
{
    cout << "\n A code by Britt Jamerson aka Da_sk8rboy--no0bsawce!"
            "\n+-----------------------------------------------------------------------+"
            "\n| Welcome to the Gaben take or go test!.                                |"
            "\n| Gaben has stolen your computer and it is up to you to get it back.    | "
            "\n| Gaben say's you must pass the Gaben take or go test! ! !              |"
            "\n+-----------------------------------------------------------------------+";
    bool clamsTaken, picklesTaken, killedByGaben;
    cout << "\n\nYou enter the first chamber."
            "\nIt's full of purple clam's, "
            "you cannot believe."
            "\nDo you take the clam's (1=Yes, 0=No)? ";
    cin >> clamsTaken;
   
    if(clamsTaken)
    {
        cout << "\nYou keep the clams, but you have failed the first test."
                "\nGame 0ver. . .\n\n";

                return 0;
    }
    else
    {
        cout << "Congratulations, "
                "you have passed the first test!"
                "\n\nYou enter the second chamber."
                " It is full of shining Pickles! ! !"
                "\nDo you take the shining pickles"
                "(1=Yes, 0=No)?";

        cin >> picklesTaken;

        if(picklesTaken)
        {
            cout << "You take the Shining Pickles, "
                    "but you have failed the second test!"
                    "\nYou've proven you're GREED. . ."
                    "\nGame 0ver. . .\n\n";

                        return 0;
        }
        else
        {
            cout << "Congratulations, you have passed the Second test!"
                    "\n\n You enter the Third chamber. "
                    "\n A no0b is being attacked by a MiniGaben!"
                    "\nDo you ignore the no0b & move on (1=Yes, 0=No)?";

            cin >> killedByGaben;
            if(killedByGaben)
            {
                cout << "\nAs you sneak by, the MiniGaben turn's his attenetion "
                        "to you."
                        "\nHe grabs you & eat's you whole with one bite. . ."
                        "You are now dead."
                        "\nGame 0ver. . .\n\n";

                                return 0;
            }
            else
            {
                cout << "Congratualations, you"
                        " have passed all three tests!\n\n"
                        "You exit the chamber & "
                        "confront Gaben.\n\n"
                        "He tries to eat you whole "
                        "but you move on.\n"
                        "With one swing of your trout it is over.\n\n"
                        "You and your computer live happily ever after.\n\n"
                        "The End. . .\n\n";
            }
        }       
        system("PAUSE");
    }
    return 0;
}


Zenith77 02-14-2007 22:00

Re: C++ help
 
You probably have a logic error (I'm to lazy to look for it right now). But you still need to do the while loop thing.

Quote:

Originally Posted by LittleDude (Post 440433)
you gotta return 0 back to the calling program so it knows to end.

That's his problem, he doesn't want it to end. And no, you don't have to return 0 or return anything for that matter (hence return type void), as most compilers know how to handle this.

Da_sk8rboy 02-14-2007 22:01

Re: C++ help
 
talking to dude.
That doesnt solve the problem i have. Still choosing ''1'' in the first test exits program.. :(

Da_sk8rboy 02-14-2007 22:03

Re: C++ help
 
Quote:

Originally Posted by Zenith77 (Post 440435)
You probably have a logic error (I'm to lazy to look for it right now). But you still need to do the while loop thing.



That's his problem, he doesn't want it to end. And no, you don't have to return 0 or return anything for that matter (hence return type void), as most compilers know how to handle this.

could you explain exactly what the loop is doing.. (im fairly new to C++) havent got to loops yet..


All times are GMT -4. The time now is 00:44.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.