Thread: Problems with functions and for loops

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    3

    Unhappy Problems with functions and for loops

    Hello,
    I''m having problems with a program which involves functions.
    The user is supposed to input the letter he wants printed out either I or F or Quit ,Q. He can start over with another letter after printing one out.
    They can be between 5 and 11 stars in height but the width is always the same. Also the letter must be only an uneven number in height say 5, 7, 9, or 11.
    The thing is the letters are always 5 in height and sometimes the letter F doesn't print out correctly if you start over after printing I.
    I'm also supposed to use embedded for loops for the letters which is not what I've done.
    Can anyone help me out?
    PHP Code:
    [CODE]

    #include <stdio.h>
    #include <ctype.h>
     
     
              // shows user what choices he has
     
    void showMenu()   { 
            
    char  IFQ;
            
            
    printf("\n    Menu\n");
            
    printf(" I : Letter I\n");
            
    printf(" F : Letter F\n");
            
    printf(" Q : Quit\n");
            
    printf(" Enter your choice:");
            }
            
    // reads choice of the user and validates it
            
    char readChoice( ) 
        
           { 
                 
    char Choice;
             
    Choice=toupper(getche());
             
           }
           
           
    // reads height of letters wanted and validates it
           
    int readHeight(int minint max )
           
        {  
    int height;
            
    printf("\n\nHeight of letter must be between 5 and 11\nEnter your height: ");
            
    scanf(" %d", &height);
             return 
    0; }
       
        
    // drawI : draws the letter I
        
    void drawIint height)   {
             
    int i;
              
             
    printf("*****\n");
             for( 
    i=0i-2<=height;i++){
             
    printf("  *  \n");
             
             }
             
    printf("*****");
             
             
    getch();
            } 

       
    // drawF : draws the letter F
        
    void drawFint height)   { 
             
    int i;
            
    printf("*****\n");
            
    printf("*\n");
            
    printf("*****\n");
             for (
    i=1i-2<=height;i++) 
            
    printf("*\n"i);
            
    scanf("%d", &i);
               }

       
    // systemPause 
        
    void Pause( )
        {   
            
    printf("\n Press any key to continue");
            
    getch();
        } 
    // end Pause 
        
      //main program
       
    int main()
       { 
         
    char  Choice;                  // users' choice
         
    int   height;                // height of the letter
         
         
    do
         {
            
    showMenu();
            
    Choice readChoice();
            if ( 
    Choice != 'Q' )
            {
                 
    height readHeight511);
                 switch (
    Choice)
                 {
                    case 
    'I' drawI(height);   break;
                    case 
    'F' drawF(height);   break;
                  }
    // end switch
            
    }  // end if 
        
    }// end while
        
    while (Choice != 'Q');
        
        
    Pause();
        

       } 
    // end main

    [/CODE
    Last edited by slava; 11-08-2008 at 08:41 PM. Reason: found solution to problem!

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Code:
    // reads height of letters wanted and validates it 
           int readHeight(int min, int max ) 
            
        {  int height; 
            printf("\n\nHeight of letter must be between 5 and 11\nEnter your height: "); 
            scanf(" %d", &height); 
             return 0; }
    readHeight() returns 0 instead of the height input by the user so its puzzling that the program will even print 5 stars ie the minimum height.
    Last edited by itCbitC; 11-08-2008 at 01:33 PM.

Popular pages Recent additions subscribe to a feed