Your SlideShare is downloading. ×
Chapter05
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Chapter05

103
views

Published on

หลักการเขียนโปรแกรมคอมพิวเตอร์เบื้องต้น โดยใช้ภาษา C# และใช้โปรแกรม RAPTOR ในการออกแบบ Flowchart

หลักการเขียนโปรแกรมคอมพิวเตอร์เบื้องต้น โดยใช้ภาษา C# และใช้โปรแกรม RAPTOR ในการออกแบบ Flowchart

Published in: Education, Technology, Sports

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
103
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 5 Selecting Programming Company LOGO
  • 2.     Boolean Expression If Nested If Switch…case
  • 3. Boolean Expression      Comparison) equal) Not equal) Less) Greater) Less than or equal to)  Greater than or equal to)
  • 4. X = 10 Y = "com") X == 10 X != 10 X < 10 X > 10 X <= 10 X >= 10 y+"puter" == "computer" Y == "Com" Y != "com" True False False False True True True False False
  • 5. Boolean Expression  Boolean) And)  Or)  Not)
  • 6. A = 10, B = 5, Y = "com", Z = true) A == 10 && B+5 == A) A + B > 10) && B == 5) (B <= A) || (B == A) !(10 == B) !(A >= B) (A == 10) && (Y == "com") (Y == "Com") || (Y == "com") (Y == "Com") || !(Z) !(!(Z)) || !(Z) True False True True False True True False True True
  • 7. If If   condition) If if if…else True else) 2 False
  • 8. If if (condition) statement; (A=5, B=10) If (A == B/2) Console.WriteLine("True"); if (condition) statement; If (B/2 == A) Console.WriteLine(B+"/2 = " + A); if (condition) { statement1; statement2; statement3; : } If (A != B) { Console.WriteLine("A = {0}",A); Console.WriteLine("B = {0}",B); Console.WriteLine("{0} != {1}",A,B); }
  • 9. static void Main(string[] args) { int A = 5; int B = 10; if (A != B) { Console.WriteLine("A = {0}", A); Console.WriteLine("B = {0}", B); Console.WriteLine("{0} != {1}", A, B); } Console.ReadKey(); }
  • 10. static void Main(string[] args) { char Member; float Discount = 0f; Console.Write("Are you Member (Y or N) : "); Member = char.Parse(Console.ReadLine()); if ((Member == 'y') || (Member == 'Y')) { Discount = 0.05f; } Console.WriteLine("Discount is {0:p}", Discount); Console.ReadLine(); }
  • 11. If…else if (condition) statement; else statement; if (condition) { statement1; statement2; : } else { statement1; statement2; : } (A=5, B=10) If (A == B) Console.WriteLine(A+" = " + B); else Console.WriteLine(A+" != " + B); If (A <= B) { Console.WriteLine("A = {0}",A); Console.WriteLine("B = {0}",B); Console.WriteLine("{0} <= {1}",A,B); } else { Console.WriteLine("A = {0}",A); Console.WriteLine("B = {0}",B); Console.WriteLine("{0} > {1}",A,B); }
  • 12. static void Main(string[] args) { int Age, Ticket; Console.Write("How old are You? : "); Age = int.Parse(Console.ReadLine()); if (Age >= 13) { Ticket = 50; } else { Ticket = 20; } Console.WriteLine("You are {0} years old", Age); Console.Write("The price of Ticket is "} Console.Write("{0} Baht", Ticket); Console.ReadLine(); }
  • 13. Nested If If If Nested If If
  • 14. Nested If if (condition) { if (condition) { statement; } } (A=13, B=60) if (A == 13) { if (B == 60) { Console.WriteLine("A = {0} and B = {1}", A, B); } }
  • 15. Nested If if (condition) { if (condition) { statement; } } else { if (condition) { statement; } } (A=13, B=60) if (salary < 1650) { SocialSecurity = 0; } else { if (salary < 15000) { SocialSecurity = salary * 0.05f; } else { SocialSecurity = 15000*0.05f; } }
  • 16. 5 A-F
  • 17. 50 If (Mark < 50) F 60 If (Mark < 60) D 70 If (Mark < 70) C 80 If (Mark < 80) B A
  • 18. 80 If (Mark >= 80) A 70 If (Mark >= 70) B 60 If (Mark >= 60) C 50 If (Mark >= 50) D F
  • 19. Switch…case C# Nested if switch...case
  • 20. switch (expression) { case constant-expression-1: statements; break; case constant-expression-2: statements; break; case constant-expression-3: statements; break; : default: statements; break; } Switch…case using System; namespace SwitchCase { class Program { static void Main(string[] args) { char Operator; int A = 5, B = 10, Total; Operator = char.Parse(Console.ReadLine()); switch(Operator) { case '+': Total = A + B; break; case '-': Total = A - B; break; case '*': Total = A * B; break; case '/': Total = A / B; break; default: Total = 0; break; } Console.WriteLine("Answer is {0}", Total); } } }
  • 21. Switch…case RAPTOR default If If switch…case switch…case char) switch…case If integer) string)
  • 22. Try…catch  C# Console.ReadLine() int int int.Parse(Console.ReadLine()) A try…catch…finally A
  • 23. int Operator = 0; int A = 5, B = 10, Total; try { Operator = int.Parse(Console.ReadLine()); } catch (Exception) { Console.WriteLine("Input is not integer...Error!!!"); } finally { Console.WriteLine("Write everytime"); }
  • 24. try...catch...finally       Run Time Process) Init Process) Block try Block catch Block finally 1 try Block catch Block finally try 1 Block
  • 25.   5 /

×