Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace UDEMY_SECTION_4
- {
- class Program
- {
- static void Main(string[] args)
- {
- //intro to decision structures
- int temp = 10;
- if (temp <10)
- {
- Console.WriteLine("Take the coat.");
- }
- if (temp == 10)
- {
- Console.WriteLine("It's 10 degrees C.");
- }
- if (temp >10)
- {
- Console.WriteLine("Cozy!");
- }
- //37 Intro to TryParse()
- string numAsString = "1281";
- int numString;
- bool success = int.TryParse(numAsString, out numString);
- if (success)
- {
- Console.WriteLine("Parsing successful, number is: " + numString);
- }
- else
- {
- Console.WriteLine("Failed parsing");
- }
- //38 If & Else If + Try Parse
- Console.WriteLine("What's the temperature like?");
- string temp2 = Console.ReadLine();
- int temp2Num;
- int num2;
- if (int.TryParse(temp2, out num2))
- {
- temp2Num = num2;
- }
- else
- {
- Console.WriteLine("Value entered was not a number. Temperature set to 0.");
- temp2Num = 0;
- }
- if (temp2Num < 10)
- {
- Console.WriteLine("Take the coat.\n");
- }
- else if (temp2Num == 10)
- {
- Console.WriteLine("It's 10 degrees C.\n");
- }
- else if(temp2Num == 30)
- {
- Console.WriteLine("Boy it's hot.\n");
- }
- else
- {
- Console.WriteLine("Cozy!\n");
- }
- //39 Nested If Statements
- bool isAdmin = false, isRegistered = true;
- string userName = "";
- Console.WriteLine("Enter in user name: ");
- userName = Console.ReadLine();
- //you could also add all ofthese into the initial if statement
- if (isRegistered)
- {
- Console.WriteLine("Hi there, registered user!");
- if (userName != "")
- {
- Console.WriteLine("Hi there, " + userName);
- if(userName == "Admin")
- {
- Console.WriteLine("Hi there, Admin!");
- }
- }
- }
- if (isAdmin || isRegistered)
- {
- Console.WriteLine("You are logged in.\n");
- }
- //40 If Statement Challenge
- Console.WriteLine("Create a username: ");
- string un = Console.ReadLine();
- Console.WriteLine("Create a password: ");
- string pw = Console.ReadLine();
- Console.WriteLine("Enter in username: ");
- string inputUN = Console.ReadLine();
- Console.WriteLine("Enter in password: ");
- string inputPW = Console.ReadLine();
- while (inputUN != un && inputPW != pw)
- {
- Console.WriteLine("Incorrect username or password. Try again.");
- Console.WriteLine("Enter in username: ");
- inputUN = Console.ReadLine();
- Console.WriteLine("Enter in password: ");
- inputPW = Console.ReadLine();
- if (inputUN == un && inputPW == pw)
- {
- Console.WriteLine("You are logged in!");
- }
- }
- Console.Read();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement