1. Do a small game of fate:
Enter the name of the man, the woman's name, Output Fate index, give advice.
static void Main1342341 (string[] args)
{
Matching the names of men and women
Console.Write ("The Man's Name:");
String m = Console.ReadLine ();
Console.Write ("Woman's Name:");
string w = Console.ReadLine ();
Random rand = new Random ();
int c = Rand. Next (100);
Console.WriteLine ("The two people's Fate index is:" +c);
if (c>0&&c<20)
{
Console. WriteLine ("You two have no part");
}
else if (c>=20&&c<40)
{
Console. WriteLine ("You two are destined to have no part");
}
else if (c >= && C < 60)
{
Console.WriteLine ("You two are attracted to each other");
}
else if (c >= && C < 80)
{
Console.WriteLine ("You two are destined to have a share");
}
else if (c >= && C < 100)
{
Console.WriteLine ("You two are a natural pair");
}
}
2. Make a small game with computer scissors. 0-Scissors, 1-stone, 2-cloth
Require output 0,1,2, the computer generates random numbers, compared with human input than the judge who wins.
static void Main1111112324 (string[] args)
{
Scissors with computer
Random rand = new Random ();
int c = Rand. Next (3);
Console. WriteLine ("You choose 0-(Scissors), 1-(stone), 2-(cloth):");
int A=convert. ToInt32 (Console. ReadLine ());
if (c = = 0)
{
Console.WriteLine ("The computer is a pair of scissors!") ");
if (a = = 0)
{
Console.WriteLine ("Tie! ");
}
else if (a = = 1)
{
Console.WriteLine ("You win! ");
}
else if (a = = 2)
{
Console.WriteLine ("You Lost!") ");
}
Else
{
Console.WriteLine ("Input Error! ");
}
}
if (c = = 1)
{
Console.WriteLine ("The computer is a stone!") ");
if (a = = 0)
{
Console.WriteLine ("You Lost!" ");
}
else if (a = = 1)
{
Console.WriteLine ("Tie! ");
}
else if (a = = 2)
{
Console.WriteLine ("You win! ");
}
Else
{
Console.WriteLine ("Input Error! ");
}
}
if (c = = 2)
{
Console.WriteLine ("The computer is out of cloth!") ");
if (a = = 0)
{
Console.WriteLine ("You win! ");
}
else if (a = = 1)
{
Console.WriteLine ("You Lost!") ");
}
else if (a = = 2)
{
Console.WriteLine ("Tie! ");
}
Else
{
Console.WriteLine ("Input Error! ");
}
}
}
3. The relationship between height and weight of men is: Height -100= weight; Lady: Height -110= weight. (try doing it yourself)
Float up and down 3 kg is normal.
Input gender, height, weight, output: normal? Fat? Skinny, too?
static void Main3333333333 (string[] args)
{
The relationship between height and weight
Console.WriteLine ("Please enter Gender:");
string s = Console.ReadLine ();
Console.WriteLine ("Please enter height cm:");
int T =convert. ToInt32 (Console.ReadLine ());
Console.WriteLine ("Please enter weight kg:");
int M =convert. ToInt32 (Console.ReadLine ());
if (s== "male")
{
if ((t-m) >=97&& (t-m) <=103)
{
Console. WriteLine ("normal");
}
else if ((t-m) <97)
{
Console. WriteLine ("fat");
}
Else
{
Console. WriteLine ("thin");
}
}
else if (s = = "female")
{
if ((t-m) >= 107 && (T-M) <= 113)
{
Console.WriteLine ("Normal");
}
else if ((T-M) < 107)
{
Console.WriteLine ("Fat");
}
Else
{
Console.WriteLine ("Thin");
}
}
Else
{
Console.WriteLine ("Can't recognize sex! ");
}
}
4. Enter the year, month, day, to determine if the date is correct?
static void Main2222 (string[] args)
{
Enter date and date to determine whether the correct
Console.WriteLine ("Enter Date:");
int y = Convert.ToInt32 (Console.ReadLine ());
if (y% = = 0 | | y% 4 = = 0 && y% 100! = 0)
{
int m = Convert.ToInt32 (Console.ReadLine ());
if (m = = 1 | | m = = 3 | | m = = 5 | | m = = 7 | | m = = 8 | | m = = | | m = = 12)
{
int d = Convert.ToInt32 (Console.ReadLine ());
if (d > 0 && D < 32)
{
Console.WriteLine ("Input Correct! ");
}
Else
{
Console.WriteLine ("Number of days entered incorrectly! ");
}
}
else if (m = = 4 | | m = = 6 | | m = = 9 | | m = = 11)
{
int d = Convert.ToInt32 (Console.ReadLine ());
if (d > 0 && D < 31)
{
Console.WriteLine ("Input Correct! ");
}
Else
{
Console.WriteLine ("Number of days entered incorrectly! ");
}
}
else if (m = = 2)
{
int d = Convert.ToInt32 (Console.ReadLine ());
if (d > 0 && D < 30)
{
Console.WriteLine ("Input Correct! ");
}
Else
{
Console.WriteLine ("Number of days entered incorrectly! ");
}
}
Else
{
Console.WriteLine ("Enter month Error! ");
}
}
Else
{
int m = Convert.ToInt32 (Console.ReadLine ());
if (m = = 1 | | m = = 3 | | m = = 5 | | m = = 7 | | m = = 8 | | m = = | | m = = 12)
{
int d = Convert.ToInt32 (Console.ReadLine ());
if (d > 0 && D < 32)
{
Console.WriteLine ("Input Correct! ");
}
Else
{
Console.WriteLine ("Number of days entered incorrectly! ");
}
}
else if (m = = 4 | | m = = 6 | | m = = 9 | | m = = 11)
{
int d = Convert.ToInt32 (Console.ReadLine ());
if (d > 0 && D < 31)
{
Console.WriteLine ("Input Correct! ");
}
Else
{
Console.WriteLine ("Number of days entered incorrectly! ");
}
}
else if (m = = 2)
{
int d = Convert.ToInt32 (Console.ReadLine ());
if (d > 0 && D < 29)
{
Console.WriteLine ("Input Correct! ");
}
Else
{
Console.WriteLine ("Number of days entered incorrectly! ");
}
}
Else
{
Console.WriteLine ("Enter month Error! ");
}
}
}
5. Enter the year, the month shows how many days this month?
static void Main33333 (string [] args)
{
Enter year month to determine the number of days in the month
Console.Write ("Please enter the Year:");
int year = Convert.ToInt32 (Console.ReadLine ());
if (year% = = 0 | | year% 4 = = 0 && Year% 100! = 0)
{
Console.Write ("Please enter the month:");
int M=convert. ToInt32 (Console. ReadLine ());
if (m==1| | m==3| | m==5| | m==7| | m==8| |m==10| | M==12)
{
Console. WriteLine ("There are 31 days this month.") ");
}
else if (m==4| | m==6| | m==9| | M==11)
{
Console. WriteLine ("There are 30 days this month.") ");
}
else if (m==2)
{
Console. WriteLine ("There are 29 days this month.") ");
}
Else
{
Console. WriteLine ("Enter month Error! ");
}
}
Else
{
Console.Write ("Please enter the month:");
int M=convert. ToInt32 (Console. ReadLine ());
if (m==1| | m==3| | m==5| | m==7| | m==8| |m==10| | M==12)
{
Console. WriteLine ("There are 31 days this month.") ");
}
else if (m==4| | m==6| | m==9| | M==11)
{
Console. WriteLine ("There are 30 days this month.") ");
}
else if (m==2)
{
Console. WriteLine ("There are 28 days this month.") ");
}
Else
{
Console. WriteLine ("Enter month Error! ");
}
}
}
}
}
6. Enter the hourly time to say hello automatically
static void Main11 (string[] args)
//{
Enter time to say hello
Console.WriteLine ("Please enter the time now:");
int a = Convert.ToInt32 (Console.ReadLine ());
if (a >= 0 && a < 6)
// {
Console.Write ("Good morning!") ");
// }
else if (a >= 6 && a < 11)
// {
Console.Write ("Good morning!") ");
// }
else if (a >= && a < 14)
// {
Console.Write ("Good afternoon!") ");
// }
else if (a >= && a < 19)
// {
Console.Write ("Good afternoon!") ");
// }
else if (a >= && a < 21)
// {
Console.Write ("Good evening!") ");
// }
else if (a >= && a <= 24)
// {
Console.Write ("Good night!" ");
// }
Else
// {
Console.Write ("Time input error");
// }
//}
7. Enter an integer within 100 to determine whether it is a positive integer
static void Main5 (string[] args)
//{
Enter a number within 100 to determine whether it is a positive integer
Console.Write ("Please enter Number:");
int a = Convert.ToInt32 (Console.ReadLine ());
if (a > 0 && a <= 100)
// {
Console.Write ("is a positive integer");
// }
Else
// {
if (a>100)
// {
Console. Write ("Number greater than 100");
// }
Else
// {
Console. Write ("Number less than 1");
// }
// }
//}
8. Enter the year to determine if the leap years
/* static void Main4 (string[] args)
{
Determine the year that is entered is leap years
Console.Write ("Please enter the Year:");
int year = Convert.ToInt32 (Console.ReadLine ());
if (year% = = 0 | | year% 4 = = 0 && Year% 100! = 0)
{
Console.Write ("is a leap year");
}
Else
Console.Write ("is common year");
}
9. Compare the maximum values in four numbers
static void Main3 (string[] args)
{
Compare the maximum values in the four numbers entered
Console.WriteLine ("Please enter four numbers:");
int A, B, C, D, Max;
A=convert.toint32 (Console. ReadLine ());
B=convert.toint32 (Console. ReadLine ());
C=convert.toint32 (Console. ReadLine ());
D=convert.toint32 (Console. ReadLine ());
if (a > B)
{
max = A;
}
Else
{
if (b > C)
{
max = b;
}
Else
{
if (C > D)
{
max = C;
}
Else
{
max = D;
}
}
}
Console.WriteLine (max);
}
10. Determine if the two digits of the input are related to 7
static void Main2 (string[] args)
{
Determine if the two digits of the input are related to 7
Console.WriteLine ("Please enter a two-digit number:");
int a = Convert.ToInt32 (Console. ReadLine ());
if (a% 7 = = 0 | | A% = = 7 | | a/10 = = 7)
{
Console.WriteLine ("Related to 7");
}
Else
{
Console.WriteLine ("Unrelated to 7");
}
}
11. Can you run over the leopard?
static void Main1 (string[] args)
{
Little game can you run over the leopard?
Console.Write ("Can you run over the leopard?" y/n ");
String a = Convert.ToString (Console.ReadLine ());
if (a = = "Y" | | a = = "Y")
{
Console.WriteLine ("You are more animals than animals");
}
Else
{
Console.WriteLine ("You Are not a beast");
}
}*/
Visual studio-c#-20160413-Conditional Statement Exercises