My_pet_squirrel
Have you seen my nutz?
+126|7061

Code:

// Designers Network
//Demonstrates logical operators

#include <iostream>
#include <string>

using namespace std;

int main()
{
    cout << "\tGame Designer's Network\n";
    int security = 0;
    
    string username;
    cout << "\nUsername: ";
    cin >> username;
    
    string password;
    cout << "Password: ";
    cin >> password;
    
    
if (username == "Penguinmom" && password == "tree")
{
                 cout << "\n Hey Mom whats cookin";
                 security = 5;
}

if (username == "Sammy" && password == "bluebunny")
{
             cout << "\nHey Sam What's up";
             security = 5;
}

if (username == "Melissa" && password == "ftblchic")
{
             cout <<"\nHow's it goin Mel?";
             security = 5;
}

if (!security)
    cout << "\n Your login failed. Please try again.";
    
    return 0;
}
This is a simple program I wrote in c++ but it runs right but everytime it either says failed log in or welcome it just closes what did I do wrong? As you can tell I'm just learning this stuff from a book by myself in my room on the floor with only the internets to help me =p anyways help would be appreciated thanks

Last edited by My_pet_squirrel (2006-07-14 10:43:51)

My_pet_squirrel
Have you seen my nutz?
+126|7061
Rosse_modest
Member
+76|7217|Antwerp, Flanders

My_pet_squirrel wrote:

I'm not so sure there's that many people on BF2S that know about programming in C++, might take a while for them to read your post and reply if they exist.

This is after all a forum for people who like to zap unsuspecting victims with shock paddles, shoot at each other in tanks and drop bombs on amphibious assault ships, not a dedicated computer forum.
My_pet_squirrel
Have you seen my nutz?
+126|7061

Rosse_modest wrote:

My_pet_squirrel wrote:

I'm not so sure there's that many people on BF2S that know about programming in C++, might take a while for them to read your post and reply if they exist.

This is after all a forum for people who like to zap unsuspecting victims with shock paddles, shoot at each other in tanks and drop bombs on amphibious assault ships, not a dedicated computer forum.
Ya well i figured most people brag how many computer languages they know and when i need a tiny bit of help nothing but ya i know what you mean I also posted on a real C++ forum and just waiting for a reply too
Reaper2325
Member
+2|7164|New Hartford, New York
I'm not sure what your trying to do, but using Borland C++ 5.01 I was able to gett it to ask for a user/pass....then if correct display the messages. If not, loop and allow you to try again.

Code:

// Designers Network
//Demonstrates logical operators

#include <iostream.h>
#include <string.h>
#include <conio.h>

//using namespace std;

int main()
{
    cout << "\tGame Designer's Network\n";
    int security = 0;

    do
    {

        char username[20];
        cout << "\nUsername: ";
        cin >> username;

        char password[20];
        cout << "Password: ";
        cin >> password;


        if (!strcmp(username,"Penguinmom") && !strcmp(password,"tree"))
        {
          cout << "\n Hey, Mom whats cookin?\n";
         security = 5;
        }

        if (!strcmp(username,"Sammy") && !strcmp(password,"bluebunny"))
        {
          cout << "\nHey Sam What's up\n";
         security = 5;
        }

        if (!strcmp(username,"Melissa") && !strcmp(password,"ftblchic"))
        {
          cout <<"\nHow's it goin Mel?\n";
         security = 5;
        }
        if (security != 5)
        {
            cout << "\n Your login failed. Please press any key to try again. \n";
            cout << "\n Press <Ctrl>+<C> to 'EXIT' ....... \n";
            getch();
            clrscr();
        }
    }
    while(security!=5);


    cout << "Game Over! \n \n";
    cout << "Press the enter key to exit";
    cin.ignore(cin.rdbuf()->in_avail() + 1);

    return 0;
}
I hope this helps some.
BellusEndus
Make love not war
+59|7064|Edinburg
use that ^^^^^
two problems with your version, for starters theres no stop point so the prog just runs through to the end and then closes, also your initialising security as an int and then treating it as a boolean. hope thats right, never used c++ just guessing.
My_pet_squirrel
Have you seen my nutz?
+126|7061
Reaper I use Dev-C++ and ya i tried it and got

scratch all of that I got it to work only 1 error now



When the pass is correct and username my program just closes without displaying welcome Why is that it is happening with everything I have tried to write so far like my calculator and my number game =/ is it a problem with my pc or just me =p

Last edited by My_pet_squirrel (2006-07-14 11:43:56)

brome
brap.
+244|7028|Accidental, TK
i think it's becuase you're telling it to return 0, and not telling it to wait.  so as soon as it fails login it thinks "ah the program's finished now" so it just closes.  my two cents
My_pet_squirrel
Have you seen my nutz?
+126|7061

brome wrote:

i think it's becuase you're telling it to return 0, and not telling it to wait.  so as soon as it fails login it thinks "ah the program's finished now" so it just closes.  my two cents
I have completely removed return 0; many times and tested it but it seems to always do this argh its a pain
Reaper2325
Member
+2|7164|New Hartford, New York
The same thing happens in C++, when the code completes it terminates the program. That's why most programs I do for work (simple C++ stuff), I to the following at the end:


Code:

        cout<<"Press Any Key To Exit......";
        getch();
        exit(1);
Basically, I tell it to wait for any key to be hit since its waiting for an input, then it terminates the program.


I revised what I did earlier to add it in.....

Code:

// Designers Network
//Demonstrates logical operators

#include <iostream.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>

void main(void)
{
    cout << "\tGame Designer's Network\n";
    int security = 0;

    do
    {

        char username[20];
        cout << "\nUsername: ";
        cin >> username;

        char password[20];
        cout << "Password: ";
        cin >> password;


        if (!strcmp(username,"Penguinmom") && !strcmp(password,"tree"))
        {
          cout << "\n Hey, Mom whats cookin?\n";
         security = 5;
        }

        if (!strcmp(username,"Sammy") && !strcmp(password,"bluebunny"))
        {
          cout << "\nHey Sam What's up\n";
         security = 5;
        }

        if (!strcmp(username,"Melissa") && !strcmp(password,"ftblchic"))
        {
          cout <<"\nHow's it goin Mel?\n";
         security = 5;
        }
        if (security != 5)
        {
            cout << "\n Your login failed. Please press any key to try again. \n";
            cout << "\n Press <Ctrl>+<C> to 'EXIT' ....... \n";
            getch();
            clrscr();
        }
    }
    while(security!=5);


    cout << "Game Over! \n \n";
    cout << "Press any key to exit";
    getch();
    exit(1);
}

Last edited by Reaper2325 (2006-07-14 11:53:34)

My_pet_squirrel
Have you seen my nutz?
+126|7061
OH ok I get it just somthing my book just left out see it kept leaving screen shots of the finished product but mine kept closing I added this to everything now they all work thank you very much
Reaper2325
Member
+2|7164|New Hartford, New York
Glad to help out
unnamednewbie13
Moderator
+2,072|7213|PNW

Take my advice:

Learn APL.
My_pet_squirrel
Have you seen my nutz?
+126|7061

unnamednewbie13 wrote:

Take my advice:

Learn APL.
Why?
unnamednewbie13
Moderator
+2,072|7213|PNW

My_pet_squirrel wrote:

unnamednewbie13 wrote:

Take my advice:

Learn APL.
Why?
http://www.chilton.com/~jimw/

Board footer

Privacy Policy - © 2025 Jeff Minard