Program I made check it out if you want...... comment.... whatever

This is a discussion on Program I made check it out if you want...... comment.... whatever within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> #include <string> #include <windows.h> using namespace std; int main() { string Header("Welcome Enter your password: \n"); string ...

  1. #1
    Registered User Sshakey6791's Avatar
    Join Date
    Nov 2008
    Location
    -
    Posts
    57

    Talking Program I made check it out if you want...... comment.... whatever

    Code:
    #include <iostream>
    #include <string>
    #include <windows.h>
    
    using namespace std;
    
    int main()
    {
    	string Header("Welcome Enter your password: \n");
    	string line(28, '*');
    	string PassWord;
    	string TheKey = "Sshakey6791";
    	string Name;
    	string RealName = "steve";
    	string Anwser;
    
    	int count = 0;
    	
    	do {
    
    
    		cout << line << endl << Header << line << endl;
    		cout << ">";
    		cin >> PassWord;
    
    		cout << endl;
    
    		if ( PassWord == TheKey ) 
    		{ 
    				cout << "Processing Information.."; Sleep(900); cout << "."; Sleep(900); cout << "."; Sleep(900); cout << ".\n";
    				cout << "Welcome back \n";
    				cout << " What is your name again?\n>";
    				cin >> Name;
    
    				cout << endl;
    				
    				if ( Name != RealName ) {
    					
    					cout << "Thinking..."; Sleep(900); cout << "."; Sleep(900); cout << "."; Sleep(900); cout << "."; Sleep(900); cout << ".\n"; 
    					Sleep(2000);
    					cout << "That's not right!\n";
    					Sleep(2000);
    					cout << "You hack this, didn't you?\n>";
    					cin >> Anwser;
    					cout << endl;
    					
    					if ( Anwser == "yes" || Anwser == "Yes" ) {
    					
    						Sleep(2000);
    						cout << "Thanks for telling me the truth.\n";
    						cout << "But you have to go.\n";
    						Sleep(2000);
    						exit(1);
    
    						cout << endl;
    						
    					} else if ( Anwser == "no" || Anwser == "No" ) {
    					
    						Sleep(2000);
    						cout << "Your a lier\n";
    						Sleep(2000);
    						cout << "The Programming is shutting down!!!\n";
    						Sleep(2000);
    						exit(1);
    
    						cout << endl;
    						
    					} else {
    					
    						cout << "Thinking..."; Sleep(900); cout << "."; Sleep(900); cout << "."; Sleep(900); cout << "."; Sleep(900); cout << ".\n";
    						Sleep(2000);
    						cout << "That is not even an anwser.\n";
    						cout << "GoodBye\n";
    						Sleep(2000);
    						exit(1);
    
    						cout << endl;
    						
    					}
    				}
    			} 
    		
    		count++;
    		
    		if ( count == 3 ) {
    		
    			cout << "Error!!\n";
    			cout << "Your being kicked. goodbye!!!\n";
    			Sleep(2000);
    			exit(1);
    			
    		}
    		
    	} while ( PassWord != TheKey );
    
    
    		if ( Name == RealName ) {
    						
    			cout << "Thinking..."; Sleep(900); cout << "."; Sleep(900); cout << "."; Sleep(900); cout << "."; Sleep(900); cout << ".\n";
    			Sleep(2000);
    			cout << "Sorry.. can never be to cauful.\n";
    			Sleep(1000);
    			cout << "Would you like to leave? \n>";
    			cin >> Anwser;
    
    			cout << endl;
    
    			if ( Anwser == "yes" || Anwser == "Yes" ) {
    
    				cout << "Goodbye.";
    				Sleep(3000);
    				exit(1);
    
    				cout << endl;
    
    			} else if ( Anwser == "no" || Anwser == "No" ) {
    
    				cout << "This program is not complete\n";
    				cout << "Sorry but program is going to end anyway\n";
    				
    			} else {
    
    				cout << "Error!!!\n";
    			}
    		}
    	
    	system("pause");
    	return(0);
    }
    After getting the password wrong 3 times the program will exit
    Last edited by Sshakey6791; 01-05-2009 at 09:41 AM.
    "Blood you have thirsted for -- now, drink your own!"
    (Dante)

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Far too many calls to Sleep.

    Your english spelling isn't very good either (trys should be tries, hack this should be hacked this).

    Code:
    						exit(1);
    
    						cout << endl;
    
    Red code never gets executed.

    Code:
    					cout << "Thinking..."; Sleep(900); cout << "."; Sleep(900); cout << "."; Sleep(900); cout << "."; Sleep(900); cout << ".\n";
    repeated at least three times - make it a function.

    Code:
    	string TheKey = "Sshakey6791";
    ...
    	string RealName = "steve";
    I think those should be "const".

    Code:
    			if ( Anwser == "yes" || Anwser == "Yes" ) {
    So "YES" is an incorrect answer, I take it...
    You are checking for yes&no in several places - make it a function that returns 0, 1, -1 or some such for No, Yes and "invalid", respectively.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User Sshakey6791's Avatar
    Join Date
    Nov 2008
    Location
    -
    Posts
    57

    Here the new one

    Code:
    #include <iostream>
    #include <string>
    #include <windows.h>
    
    using namespace std;
    
    int main()
    {
    	const string HEADER ( "\t\t\tThree chances to get password right\n\n" );
    	const string line ( 80, '*' );
    	const string KeyWord = "metal";
    	const string ThePassWord = "Sshakey6791";
    	string PassWord;
    	string NameEnter;
    	const string Name = "Steve";
    	string Answer;
    	string Type_Answer;
    	int count = 0;
    
    	cout << line << endl;
    	cout << HEADER;
    	cout << line << endl;
    
    	while ( true ) {
    
    		cout << "Enter name: ";
    		cin >> NameEnter;
    
    		if ( NameEnter != Name ) {
    			cout << NameEnter << " is not a valid. Please try again. \n\n";
    
    		} else if ( NameEnter == Name ) {
    
    			break;
    		}
    	}
    
    	do {
    
    		cout << "Enter password: ";
    		cin >> PassWord;
    
    		if ( PassWord == ThePassWord ) {
    
    			cout << "\nWhat is your favorit type of music?\n>";
    			cin >> Type_Answer;
    
    			if ( Type_Answer == KeyWord ) {
    
    				cout << "Welcome back "<< Name << endl;
    
    			} else {
    
    
    				cout << "\nYour not " << Name << endl;
    				cout << "Then who are your?\n>";
    				cin >> Answer;
    
    				if ( Answer == Name ) {
    
    
    					cout << "Your a bad lier. " << Name << " doesn't like " << Type_Answer << endl;
    					cout << "You have to go. GoodBye.\n";
    
    					system("pause");
    
    					return -1;
    
    				} else {
    					
    					cout << "Ooo so your name is " << Answer << ". Well you have to go sorry.\n";
    				}
    			}
    
    		}
    
    		count++;
    
    		if ( count == 3 )
    			break;
    
    
    	} while ( PassWord != ThePassWord );
    
    	system("pause");
    
    	return(0);
    }
    Thanks for the tips... but most of the mistakes wear because I was in school and only had 15 min left in class and wanted to post it before class ended...
    Last edited by Sshakey6791; 01-05-2009 at 04:27 PM.
    "Blood you have thirsted for -- now, drink your own!"
    (Dante)

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    	while ( true ) {
    
    		cout << "Enter name: ";
    		cin >> NameEnter;
    
    		if ( NameEnter != Name ) {
    			cout << NameEnter << " is not a valid. Please try again. \n\n";
    			continue;
    
    		} else if ( NameEnter == Name ) {
    
    			break;
    		}
    	}
    Not needed - the loop will always continue unless you specifically break it
    The first if determines that NameEnter is NOT Name, so it's got to be the same if that comparison is NOT true - so no need to compare again in a second else.

    Code:
    			if ( Type_Answer == KeyWord ) {
    
    				cout << "Welcome back "<< Name << endl;
    
    			} else if ( Type_Answer != KeyWord ) {
    Like above, you are comparing something, and then comparing to see if it's the other variant - there are only two options: TypeAnswer is equal to KeyWord, or it is NOT equal - it must be one of those too - so you do not need to check the second option in the else, because we KNOW it is not the first option.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User Sshakey6791's Avatar
    Join Date
    Nov 2008
    Location
    -
    Posts
    57
    Ooo I see thanks for the help man.....
    "Blood you have thirsted for -- now, drink your own!"
    (Dante)

  6. #6
    Registered User Sshakey6791's Avatar
    Join Date
    Nov 2008
    Location
    -
    Posts
    57

    New Password protector..... Check it out

    Code:
    #include <iostream>
    #include <string>
    
    
    using namespace std;
    
    int main()
    {
    	const string HEADER ( "\t\t\tThree chances to get password right\n\n" );
    	const string line ( 80, '*' );
    	const string KeyWord = "metal";
    	string ThePassWord = "Sshakey6791";
    	string DefaultPassWord = "music";
    	string PassWord;
    	string NameEnter;
    	const string Name = "Steve";
    	string Answer;
    	string Type_Answer;
    	int count = 0;
    
    	cout << line << endl;
    	cout << HEADER;
    	cout << line << endl;
    
    	while ( true ) {
    
    		cout << "Enter name: ";
    		cin >> NameEnter;
    
    		if ( NameEnter != Name ) {
    			cout << NameEnter << " is not a valid. Please try again. \n\n";
    
    		} else if ( NameEnter == Name ) {
    
    			break;
    		}
    	}
    
    	do {
    
    		cout << "Enter password: ";
    		cin >> PassWord;
    		
    
    		if ( PassWord == ThePassWord ) {
    
    			cout << "\nWhat is your favorit type of music?\n>";
    			cin >> Type_Answer;
    
    			if ( Type_Answer == KeyWord ) {
    
    				cout << "Welcome back "<< Name << endl;
    
    			} else {
    
    
    				cout << "\nYour not " << Name << endl;
    				cout << "Then who are your?\n>";
    				cin >> Answer;
    
    				if ( Answer == Name ) {
    
    					cout << "Your a bad lier. " << Name << " doesn't like " << Type_Answer << endl;
    					cout << "You have to go. GoodBye.\n";
    					cin.get();
    
    				} else {
    					
    					cout << "Ooo so your name is " << Answer << ". Well you have to go sorry.\n";
    					cin.get();
    				}
    			}
    
    		}
    
    		count++;
    
    		if ( count == 3 ) {
    
    			cout << "Password has been changed\n";
    			
    			ThePassWord.swap (DefaultPassWord);
    		}		
    
    
    	} while ( PassWord != ThePassWord );
    
    
    	return(0);
    }
    "Blood you have thirsted for -- now, drink your own!"
    (Dante)

  7. #7
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Code:
    		if ( NameEnter != Name ) {
    			cout << NameEnter << " is not a valid. Please try again. \n\n";
    
    		} else if ( NameEnter == Name ) {
    
    			break;
    		}
    Refer to what matsp said.



    lier = liar
    favorit = favorite
    GoodBye = Goodbye
    PassWord = Password
    KeyWord = Keyword
    Your not = You're not || You are not
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  8. #8
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    Quote Originally Posted by Sshakey6791 View Post
    Thanks for the tips... but most of the mistakes wear because I was in school and only had 15 min left in class and wanted to post it before class ended...
    I admire the dedication, but you should probably pay more attention to class while in class...
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  2. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 07:35 AM
  3. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  4. What's the best program you have ever made?
    By Kevin.j in forum A Brief History of Cprogramming.com
    Replies: 31
    Last Post: 10-02-2002, 11:29 AM
  5. Can someone check my program?
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 10-04-2001, 07:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21