Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <stdlib.h>
- #include <fstream>
- #include <time.h>
- #include <vector>
- using namespace std;
- int main()
- {
- menu:
- system("cls");
- string choice;
- string username;
- string passLength;
- string lowercases = "abcdefghijklmnopqrstuvqxyz";
- string uppercases = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- string numbers = "1234567890";
- string symbols = "`~!@#$%^&*()_+-={[}]|\:'<,>.?/";
- string password;
- string sym;
- string num;
- string upper;
- string lower;
- string choices[4];
- string exit;
- string word;
- string strx;
- bool playingGame = true;
- int inty;
- int intx;
- int number;
- bool upperCase = false;
- bool lowerCase = false;
- bool IsSymbols = false;
- bool IsNumbers = false;
- bool requiredLength = true;
- bool userLength = true;
- bool length = true;
- bool isLetter = false;
- bool response1 = true;
- bool response2 = true;
- bool response3 = true;
- bool response4 = true;
- bool palindromeIdentifier = true;
- cout << " Main Menu" << endl;
- cout << " ----------------" << endl;
- cout << endl;
- cout << "Choose a program to run:" << endl;
- cout << endl;
- cout << "1. Password Generator" << endl;
- cout << "2. Palindrome Identifier" << endl;
- cout << "3. FizzBuzz" << endl;
- cout << endl;
- cout << "4. Exit" << endl;
- cout << endl;
- getline(cin, choice);
- if (choice == "1")
- {
- system("cls");
- srand(time(NULL));
- while (userLength)
- {
- cout << "Enter a username:" << endl;
- getline(cin, username);
- if (username.length() >= 1)
- {
- userLength = false;
- cout << endl;
- }
- else
- {
- cout << "You must enter at least 1 character" << endl;
- cout << endl;
- }
- }
- while (requiredLength)
- {
- cout << "Enter a length for your password (At least 15 characters recommended):" << endl;
- getline(cin, passLength);
- cout << endl;
- try
- {
- intx = stoi(passLength);
- }
- catch (invalid_argument)
- {
- intx = 0;
- }
- if (intx <= 5 || intx >= 129)
- {
- cout << "You must enter number between between 6 and 128." << endl;
- cout << endl;
- }
- else
- {
- requiredLength = false;
- }
- }
- while (response1)
- {
- cout << "Include uppercase characters?: (yes/no)" << endl;
- getline(cin, upper);
- if (upper == "yes" || upper == "Yes" || upper == "y")
- {
- upperCase = true;
- response1 = false;
- }
- else if (upper == "no" || upper == "No" || upper == "n")
- {
- uppercases.clear();
- response1 = false;
- }
- else
- {
- cout << endl;
- cout << "Please type yes or no." << endl;
- }
- cout << endl;
- }
- while (response2)
- {
- cout << "Include lowercase characters?: (yes/no)" << endl;
- getline(cin, lower);
- if (lower == "yes" || lower == "Yes" || lower == "y")
- {
- lowerCase = true;
- response2 = false;
- }
- else if (lower == "no" || lower == "No" || lower == "n")
- {
- lowercases.clear();
- response2 = false;
- }
- else
- {
- cout << endl;
- cout << "Please type yes or no." << endl;
- }
- cout << endl;
- }
- while (response3)
- {
- cout << "Include numbers?: (yes/no)" << endl;
- getline(cin, num);
- if (num == "yes" || num == "Yes" || num == "y")
- {
- IsNumbers = true;
- response3 = false;
- }
- else if (num == "no" || num == "No" || num == "n")
- {
- numbers.clear();
- response3 = false;
- }
- else
- {
- cout << endl;
- cout << "Please type yes or no." << endl;
- }
- cout << endl;
- }
- while (response4)
- {
- cout << "Include symbols?: (yes/no)" << endl;
- getline(cin, sym);
- if (sym == "yes" || sym == "Yes" || sym == "y")
- {
- IsSymbols = true;
- response4 = false;
- }
- else if (sym == "no" || sym == "No" || sym == "n")
- {
- symbols.clear();
- response4 = false;
- }
- else
- {
- cout << endl;
- cout << "Please type yes or no." << endl;
- }
- cout << endl;
- }
- choices[0] = lowercases;
- choices[1] = uppercases;
- choices[2] = symbols;
- choices[3] = numbers;
- if (IsSymbols || IsNumbers || lowerCase || upperCase == true)
- {
- while (length)
- {
- if (password.length() == intx)
- {
- length = false;
- cout << "Your username is: " << username << endl;
- cout << "Your password is: " << password << endl;
- ofstream file;
- file.open("C:/Users/iD Student/Desktop/" + username + ".txt");
- file << "Username: " << username << endl;
- file << "Password: " << password << endl;
- file.close();
- cout << endl;
- cout << "Your login has been saved to the desktop as " << username << ".txt" << endl;
- cout << endl;
- cout << "Press enter to return to the menu." << endl;
- getline(cin, exit);
- system("cls");
- goto menu;
- }
- else
- {
- number = rand() % 4;
- if (choices[number].length() >= 1)
- {
- password += choices[number][rand() % choices[number].length()];
- }
- else
- {
- number = rand() % 4;
- }
- }
- }
- }
- else
- {
- cout << "You must pick at least one type of character to generate a password." << endl;
- cout << "Press enter to return to the menu." << endl;
- getline(cin, exit);
- system("cls");
- goto menu;
- }
- }
- else if (choice == "2")
- {
- system("cls");
- cout << "Insert a word:" << endl;
- getline(cin, word);
- while (palindromeIdentifier)
- {
- if (word.length() <= 1)
- {
- cout << "That is a palindrome." << endl;
- palindromeIdentifier = false;
- cout << "Press enter to return to the menu." << endl;
- cout << endl;
- getline(cin, exit);
- system("cls");
- goto menu;
- }
- else if (word[0] == word[word.length() - 1])
- {
- word.erase(word.begin());
- word.erase(word.end() - 1);
- }
- else
- {
- cout << "That is not a palindrome." << endl;
- palindromeIdentifier = false;
- cout << "Press enter to return to the menu." << endl;
- cout << endl;
- getline(cin, exit);
- system("cls");
- goto menu;
- }
- }
- }
- else if (choice == "3")
- {
- system("cls");
- while (playingGame)
- {
- cout << "Insert a number" << endl;
- getline(cin, strx);
- cout << endl;
- try
- {
- inty = stoi(strx);
- }
- catch (invalid_argument)
- {
- inty = 2;
- }
- if ((inty % 3 == 0) && (inty % 5 == 0))
- {
- cout << "FizzBuzz" << endl;
- cout << endl;
- cout << "Press enter to return to the menu." << endl;
- getline(cin, exit);
- system("cls");
- goto menu;
- }
- else if (inty % 3 == 0)
- {
- cout << "Buzz" << endl;
- cout << endl;
- cout << "Press enter to return to the menu." << endl;
- getline(cin, exit);
- system("cls");
- goto menu;
- }
- else if (inty % 5 == 0)
- {
- cout << "Fizz" << endl;
- cout << endl;
- cout << "Press enter to return to the menu." << endl;
- getline(cin, exit);
- system("cls");
- goto menu;
- }
- else
- {
- cout << "The number must be divisible by 3, 15, or both." << endl;
- cout << endl;
- }
- }
- }
- else if (choice == "4")
- {
- system("exit");
- }
- else
- {
- cout << "Please select a valid option." << endl;
- cout << "Press enter to restart" << endl;
- getline(cin, exit);
- goto menu;
- }
- }
Add Comment
Please, Sign In to add comment