Range check
This presentation is the property of its rightful owner.
Sponsored Links
1 / 4

int age;1-100 int score;0-100 int month;1-12 char sex;'M' or 'F' PowerPoint PPT Presentation


  • 38 Views
  • Uploaded on
  • Presentation posted in: General

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)? ");

Download Presentation

int age;1-100 int score;0-100 int month;1-12 char sex;'M' or 'F'

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Int age 1 100 int score 0 100 int month 1 12 char sex m or f

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 ();


Int age 1 100 int score 0 100 int month 1 12 char sex m or f

/* 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");

}


Int age 1 100 int score 0 100 int month 1 12 char sex m or f

/* 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 (!(ansans))

printf ("Error\n");

}while ( !);


Int age 1 100 int score 0 100 int month 1 12 char sex m or f

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 );


  • Login