Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

My C++ password program code works but...

I have written a small program with no graphics just a dos screen and some input and output functions because thats all I know how to do. When I run and compile this program for Visual C++ it works fine and all of its functions, but when I try to build it in Visual C++ or open it outside of Visual C++ as a regular exe file the program shuts down before I can get it to perform all of it's functions. My code is listed below.

Heres my Code:

#include
using namespace std;

int main()

{

int password;
int number;

number = 1, 2, 3;

password = 13245;

cout<< "Please enter your password.";
cout<< endl;
cin>> password;


if(password == 13245)

{
cout<< "Select your desierd information.";
cout<< endl;
cout<< "Press 1 for Hotmail, 2 for Programmers Heavem, and 3 for Bleepnet.";
cout<< endl;

}

else
{
cout<< "Sorry, the password you enterd is incorrect .";
cout<< endl;
return 0;
}

cin>> number;
if(number == 1)

{

cout<< "Your Hotmaild Name and Password is nothing - nothing.";
cout<< endl;
return 0;
}

if(number == 2)

{
cout<< "Your Name and password for Programmers Heaven is nothing - nothing.";
cout<< endl;
return 0;
}

if(number == 3)

{
cout<< "Your Bleepnet name and password is nothing - nothing.";
cout<< endl;
return 0;
}

else
{
cout<< " Sorry, that directory does not exist.";


}

return 1;

}

Comments

  • PentenPenten Member Posts: 21
    [b][red]This message was edited by Penten at 2003-7-2 6:31:23[/red][/b][hr]
    : I have written a small program with no graphics just a dos screen and some input and output functions because thats all I know how to do. When I run and compile this program for Visual C++ it works fine and all of its functions, but when I try to build it in Visual C++ or open it outside of Visual C++ as a regular exe file the program shuts down before I can get it to perform all of it's functions. My code is listed below.
    :
    : Heres my Code:
    :
    : #include
    : using namespace std;
    :
    : int main()
    :
    : {
    :
    : int password;
    : int number;
    :
    : number = 1, 2, 3;
    :
    : password = 13245;
    :
    : cout<< "Please enter your password.";
    : cout<< endl;
    : cin>> password;
    :
    :
    : if(password == 13245)
    :
    : {
    : cout<< "Select your desierd information.";
    : cout<< endl;
    : cout<< "Press 1 for Hotmail, 2 for Programmers Heavem, and 3 for Bleepnet.";
    : cout<< endl;
    :
    : }
    :
    : else
    : {
    : cout<< "Sorry, the password you enterd is incorrect .";
    : cout<< endl;
    : return 0;
    : }
    :
    : cin>> number;
    : if(number == 1)
    :
    : {
    :
    : cout<< "Your Hotmaild Name and Password is nothing - nothing.";
    : cout<< endl;
    : return 0;
    : }
    :
    : if(number == 2)
    :
    : {
    : cout<< "Your Name and password for Programmers Heaven is nothing - nothing.";
    : cout<< endl;
    : return 0;
    : }
    :
    : if(number == 3)
    :
    : {
    : cout<< "Your Bleepnet name and password is nothing - nothing.";
    : cout<< endl;
    : return 0;
    : }
    :
    : else
    : {
    : cout<< " Sorry, that directory does not exist.";
    :
    :
    : }
    :
    : return 1;
    :
    : }
    :
    :
    [blue]it works in Dev's C++ so check if you selected a new console application or a new windows application. otherwise i don't know.


  • WerewolfWareWerewolfWare Member Posts: 304
    : I have written a small program with no graphics just a dos screen and some input and output functions because that’s all I know how to do. When I run and compile this program for Visual C++ it works fine and all of its functions, but when I try to build it in Visual C++ or open it outside of Visual C++ as a regular exe file the program shuts down before I can get it to perform all of it's functions. My code is listed below.
    :
    : Heres my Code:
    :
    : #include
    : using namespace std;
    :
    : int main()
    :
    : {
    :
    : int password;
    : int number;
    :
    : number = 1, 2, 3;
    :
    : password = 13245;
    :
    : cout<< "Please enter your password.";
    : cout<< endl;
    : cin>> password;
    :
    :
    : if(password == 13245)
    :
    : {
    : cout<< "Select your desierd information.";
    : cout<< endl;
    : cout<< "Press 1 for Hotmail, 2 for Programmers Heavem, and 3 for Bleepnet.";
    : cout<< endl;
    :
    : }
    :
    : else
    : {
    : cout<< "Sorry, the password you enterd is incorrect .";
    : cout<< endl;
    : return 0;
    : }
    :
    : cin>> number;
    : if(number == 1)
    :
    : {
    :
    : cout<< "Your Hotmaild Name and Password is nothing - nothing.";
    : cout<< endl;
    : return 0;
    : }
    :
    : if(number == 2)
    :
    : {
    : cout<< "Your Name and password for Programmers Heaven is nothing - nothing.";
    : cout<< endl;
    : return 0;
    : }
    :
    : if(number == 3)
    :
    : {
    : cout<< "Your Bleepnet name and password is nothing - nothing.";
    : cout<< endl;
    : return 0;
    : }
    :
    : else
    : {
    : cout<< " Sorry, that directory does not exist.";
    :
    :
    : }
    :
    : return 1;
    :
    : }
    :
    :

    Of course it will be closed - it's a WIN32 based program when it is built in MSVC.
    This kind of programs should be runned phisically by MS-DOS.
    But there is another solution - you can include the <cinio.h>
    header file and add the "getch();" function befor shutting down the program at each time you write "return 0;".
    By the way, you should really learn MS-DOS C language, after all, C++ is an advance C.
    You could also use the function "system()" which defined in
    like this - system("pause");
    The system function commite's a dos command (MS use this command when the program you compiled is runned within the MSVC program).
    Hope I helped.
    Bye - from WEREWOLF.
Sign In or Register to comment.