Range check 範圍檢查: int age; int score; int month; 1-12

Slides:



Advertisements
Similar presentations
#include void main() { float x = 1.66, y = 1.75; printf(%f%f,ceil(x), floor(y)); }
Advertisements

Recursive Descent Technique CMSC 331. UMBC 2 The Header /* This program matches the following A -> B { '|' B } B -> C { '&' C } C -> D { '^' D } D ->
For(int i = 1; i
BNF <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Fundamental of C programming
DS:Lab-1 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Array_strcpy void array_strcpy(char dest[], char src[]) { int i = 0; while (src[i] != '\0') { dest[i] = src[i]; i++; } dest[i] = '\0'; }
Sort the given string, without using string handling functions.
1 DATA ABSTRACTION: USER DEFINED TYPES AND THE CLASS.
By Senem Kumova Metin 1 POINTERS + ARRAYS + STRINGS REVIEW.
Solution April 13, #include int main( void ) { int salaries[ 11 ] = { 0 }; /*total salary */ int sales; /* sales per karyawan */ double salary;
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
IF-ELSE IF-ELSE STATEMENT SWITCH-CASE STATEMENT Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Return function Random function Recursion function Function in C 1.
Dr. Soha S. Zaghloul2 Let arr be an array of 20 integers. Write a complete program that first fills the array with up to 20 input values. Then, the program.
Selection-making Decisions Selection allows you to choose between two or more possible program flow --- it lets you make decisions in your program. Examples.
Sudeshna Sarkar, IIT Kharagpur 1 Functions Lecture
Char ch; ch ‘L’‘X’‘V’‘I’ As in Roman numerals Want to give each a value, n say switch (ch) { case ‘I’:n = 1; break; case ‘V’:n = 5; break; … default:cout.
LOOPING IN C. What would be the output of the following program main( ) { int j ; while ( j
Agenda  Basic Logic - Continued...  if else statements  switch Statements  Compound Conditions.
C syntax (simplified) BNF. Program ::= [ ] Directives ::= [ ] ::= | |… ::=#include > ::=#define.
The reading is 7.38 mm. The reading is 7.72 mm.
Lesson #4 Logical Operators and Selection Statements.
Tutorial #4 Summer 2005.
Lesson #4 Logical Operators and Selection Statements.
Decision making If.. else statement.
Control Structures and Data Files
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
Compound Condition Break , Continue Switch Statements in Java
Decisions Chapter 4.
Module 7: Input/Output Operations ITEI102 Introduction to Programming
Condition Statements.
The C “switch” Statement
Arrays, Part 1 of 2 Topics Definition of a Data Structure
2008/11/24: Lecture 19 CMSC 104, Section 0101 John Y. Park
CSI 121 Structured Programming Language Lecture 7: Input/Output
The C “switch” Statement
2008/11/24: Lecture 19 CMSC 104, Section 0101 John Y. Park
Writing a program with conditionals
Chapter 5 Decision Making and Branching
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
The switch Statement Topics Multiple Selection switch Statement
The switch Statement Topics Multiple Selection switch Statement
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Decision making If statement.
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Hmjngj jxhngh.
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Relational, Logical, and Equality Operators
REPETITION STATEMENTS
Chapter 10 Structures and Unions
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Control Structure: Selection (Part 2)
Arrays I Handling lists of data.
Character Arrays char string1[] = “first”;
ECE 103 Engineering Programming Chapter 22 Selection
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
The switch Statement Topics Multiple Selection switch Statement
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Arrays, Part 2 of 2 Topics Array Names Hold Address How Indexing Works
Presentation transcript:

Range check 範圍檢查: int age; 1-100 int score; 0-100 int month; 1-12 char sex; 'M' or 'F' char house; 'L','M','C','S' char ans; 'y' or 'n' /* 1a */ do{ printf ("Q: age(1-100)? "); scanf if(…) printf ("Error\n"); }while ( );

/* 1b */ do{ printf ("Q: age(1-100)? "); scanf ("%d", &age); }while ( ! ); if ( ) printf("Error\n"); /* 1c */ while ( ){ printf ("Q: age(1-100)? "); scanf ("%d", &age); if ( ! ) printf("Error\n"); }

/* 2a */ do{ printf ("Q: are you hungry<y/n>? "); scanf ("%c", &ans); ans = (ans); }while ( ); /* 2b */ do{ printf ("Q: are you hungry<y/n>? "); scanf ("%c", &ans); if (!(ans ans )) printf ("Error\n"); }while ( ! );

if (!(mm>=1 && mm<=12 && dd>=1 && dd<= )) switch ( ) { case 2: case 4: case 6: case 9: case 11: default: } /* 3a */ do{ printf ("Q: month (1-12)? "); scanf ("%d", &mm); printf ("Q: day (1-31)? "); scanf ("%d", &dd); if(mm== ) max = 28; else if( ) max = 30; else max = ___ if (!(mm>=1 && mm<=12 && dd>=1 && dd<= )) printf ("Error - out of range!\n"); }while (mm || mm || dd || dd );