Howdy, Stranger!

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

Categories

My simple C++ program will not run fully?

Garrett85Garrett85 Member Posts: 168
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

  • NytbladeNytblade Member Posts: 56
    : 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;
    :
    : }
    :
    :

    for one thing, my advice would be to make all the ifs a switch statement. Do that to clean things up, and also I'm not does the statement "number = 1, 2, 3; " compile w/o errors? I've never seen that before nor have I tried it.

    --Nytblade


Sign In or Register to comment.