Advertisement
J2112O

scanf and function help needed

May 17th, 2015
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.45 KB | None | 0 0
  1.     2 #include <stdio.h>                                                              
  2.     3 #include <stdlib.h>                                                            
  3.     4 void verify(int check);                                                        
  4.     5 void limit(int stop);                                                          
  5.     6 int main(void)                                                                  
  6.     7 {                                                                              
  7.     8     int s = 0;                                                                  
  8.     9                                                                                
  9.    10     printf("Enter a stopping value (0-100): ");                                
  10.    11     scanf("%i", &s);                                                            
  11.    12     verify(s);                                                                  
  12.    13     limit (s);                                                                  
  13.    14     return(0);                                                                  
  14.    15 }                                                                              
  15.    16 void limit(int stop)                                                            
  16.    17 {                                                                              
  17.    18     int x = 0;                                                                  
  18.    19                                                                                
  19.    20     for(x=0; x<=100; x=x+1) {                                                  
  20.    21         printf("%i ", x);                                                      
  21.    22         if(x==stop) {                                                          
  22.    23             puts("You won!");                                                  
  23.    24             return;                                                            
  24.    25         }                                                                      
  25.    26     }                                                                          
  26.    27     puts("I won!");                                                            
  27.    28 }    
  28.    29 void verify(int check)                                                          
  29.    30 {                                                                              
  30.    31     int x = 0;                                                                  
  31.    32                                                                                
  32.    33     if(scanf("%i", &x)<= 100) {                                                
  33.    34         if(x <= 100) {                                                          
  34.    35         printf("That value is TRUE and acceptable.\n");                        
  35.    36         return;                                                                
  36.    37         }                                                                      
  37.    38     if(x > 101) {                                                              
  38.    39     printf("That value is FALSE and not acceptable.\n");                        
  39.    40     }                                                                          
  40.    41 }                                                                              
  41.    42 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement