c#기초: 로그인,회원가입 코드 만들기
using System;
namespace Hello_World
{
class Program
{
static string username;
static string password;
static void Main(string[] args)
{
Register();
Login();
Console.Read();
}
public static void Register()
{
Console.WriteLine("Please enter your username");
username = Console.ReadLine();
Console.WriteLine("Please enter your password");
password = Console.ReadLine();
Console.WriteLine("Registeration completed");
Console.WriteLine("------------------");
}
public static void Login()
{
Console.WriteLine("Please enter your username");
if (username == Console.ReadLine())
{
Console.WriteLine("Please enter your password");
if (password == Console.ReadLine())
{
Console.WriteLine("Login successful");
}
else
{
Console.WriteLine("Login failed, wrong password. Restart Program");
}
}
else
{
Console.WriteLine("Login failed, wrong username");
}
}
}
}
최고점수 누군지 코드만들기
using System;
namespace Hello_World
{
class Program
{
static int highscore = 360;
static string highscorePlayer = "Haribo";
static void Main(string[] args)
{
CheckHighscore(250, "Maria");
CheckHighscore(315, "Michael");
CheckHighscore(370, "Denis");
Console.Read();
}
public static void CheckHighscore(int score, string playerName)
{
if (score > highscore)
{
highscore = score;
highscorePlayer = playerName;
Console.WriteLine("New highscore is " + score);
Console.WriteLine("It is now held by " + playerName);
}
else
{
Console.WriteLine("The old highscore could not be broken. It is still "
+ highscore + "and held by " + highscorePlayer);
}
}
}
}
'c#(유데미)' 카테고리의 다른 글
C#:객체 Car클래스 메서드 이용하기/배열arrays(3D차원) (0) | 2023.10.03 |
---|---|
c#:do while 구문/loops/평균점수값 구하기 (0) | 2023.10.03 |
C#:user input (0) | 2023.09.27 |
c# WriteLine(),ReadLine()/ string with a slash, colon \\var,let,const (0) | 2023.09.17 |
c#씨샵: 기초 변수 선언 substring, ToLower,Trim,IndexOf,Concat(),IsNullOrWhiteSpace/문자열""구분해주는법, \n:줄바꿈 (0) | 2023.09.10 |