1 / 4

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 (&quot;Q: age(1-100)? &quot;); scanf if(…) printf (&quot;Error<br>&quot;); }while ( );. /* 1b */ do{ printf (&quot;Q: age(1-100)? &quot;);

Télécharger la présentation

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  3. /* 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 ( ! );

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

More Related