Thread: program compiles but dont work??

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    17

    program compiles but dont work??

    i need some hints on whats up with my program. to give you some back ground info, its for my minefield game. specifically this is the part of the code that keeps track of the game stats. the three things to be kept up to date are the score, number of flags and number of mines.

    i wrote a simple driver that test the functions responsible for this task. and included only one of the updating function because all three are exactly the same.

    Code:
    #include "display.h"
    #include "stats.h"
    #include <stdio.h>
    
    int main()
    {
            int up_mines = 0;
            int up_flags = 0;
            int up_score = 0;
            char x;
    
            stats(up_mines, up_flags, up_score); 
            printf("Please enter number:");
            
            while((x = getchar()) != EOF)
            {
                    update_mines(x);
                    update_flags(x);
                    update_score(x);
            }
    
    }
    Code:
    void update_mines(int up_mines)
    {
            char i;
            int k = 0;
    
            while((i = getchar(up_mines)) && k < 2)
            {
                    numbers(i);
                    k++;
            }
    }
    Code:
    #include "stats.h"
    #define MAX_STAT_ROW 4
    #define MAX_STAT_COL 3
    
    
    /* tests and chooses the number to be printed in the stats board */
    void numbers(char x)
    {
            char num1[MAX_STAT_ROW][MAX_STAT_COL];
            int i;
            int k;
            
            /* initializes all arrays to blanks */
            for(i = 0; i < MAX_STAT_ROW; i++)
            {       for(k = 0; k < MAX_STAT_COL; k++)
                    {num1[i][k] = ' ';}
            }
    
            switch(x)
            {
                    case '0':
                            num1[0][1] = '-';
                            num1[1][0] = '|';
                            num1[1][2] = '|';
                            num1[2][0] = '|';
                            num1[2][2] = '|';
                            num1[3][1] = '-';
                            for(i = 0; i < MAX_STAT_ROW; i++)
                            {       for(k = 0; k < MAX_STAT_COL; k++)
                             {printf("&#37;c", num1[i][k]);}
                            }
                            break;
                    case '1':
                            num1[1][1] = '|';
                            num1[2][2] = '|';
                            for(i = 0; i < MAX_STAT_ROW; i++) 
                            {       for(k = 0; k < MAX_STAT_COL; k++)
                             {printf("%c", num1[i][k]);}
                            }
                            break;
                    case '2':
                            num1[0][1] = '-';
                            num1[1][2] = '|';
                            num1[1][1] = '_';
                            num1[2][0] = '|';
                            num1[3][1] = '-';
                            for(i = 0; i < MAX_STAT_ROW; i++)  
                            {       for(k = 0; k < MAX_STAT_COL; k++)
                             {printf("%c", num1[i][k]);}
                            }
                            break;
                    case '3':
                            num1[0][1] = '-';
                            num1[1][2] = '|';
                            num1[1][1] = '_';
                            num1[2][2] = '|';
                            num1[3][1] = '-';
                            for(i = 0; i < MAX_STAT_ROW; i++)  
                            {       for(k = 0; k < MAX_STAT_COL; k++)
                             {printf("%c", num1[i][k]);}
                            }
                            break;
                    case '4':
                            num1[0][0] = '|';
                            num1[1][0] = '|';
                            num1[1][1] = '_';
                            num1[1][2] = '|';
                            num1[0][2] = '|';
                            num1[2][2] = '|';
                            num1[3][2] = '|';
                            for(i = 0; i < MAX_STAT_ROW; i++)  
                            {       for(k = 0; k < MAX_STAT_COL; k++)
                             {printf("%c", num1[i][k]);}
                            }
                            break;
                    case '5':
                            num1[0][1] = '-';
                            num1[1][0] = '|';
                            num1[1][1] = '_';
                            num1[2][2] = '|';
                            num1[3][1] = '-';
                            for(i = 0; i < MAX_STAT_ROW; i++)  
                            {       for(k = 0; k < MAX_STAT_COL; k++)
                             {printf("%c", num1[i][k]);}
                            }
                            break;
                    case '6':
                            num1[0][1] = '-';
                            num1[1][0] = '|';
                            num1[2][0] = '|';
                            num1[3][1] = '-';
                            num1[2][2] = '|';
                            num1[1][1] = '_';
                            for(i = 0; i < MAX_STAT_ROW; i++)  
                            {       for(k = 0; k < MAX_STAT_COL; k++)
                             {printf("%c", num1[i][k]);}
                            }
                            break;
                    case '7':
                            num1[0][1] = '_';
                            num1[1][2] = '|';
                            num1[2][2] = '|';
                            num1[1][0] = '|';
                            for(i = 0; i < MAX_STAT_ROW; i++)  
                            {       for(k = 0; k < MAX_STAT_COL; k++)
                             {printf("%c", num1[i][k]);}
                            }
                            break;
                    case '8':
                            num1[0][1] = '-';
                            num1[1][0] = '|';
                            num1[1][2] = '|';
                            num1[2][0] = '|';
                            num1[2][2] = '|';
                            num1[3][1] = '-';
                            num1[1][1] = '_';
                            for(i = 0; i < MAX_STAT_ROW; i++)  
                            {       for(k = 0; k < MAX_STAT_COL; k++)
                             {printf("%c", num1[i][k]);}
                            }
                            break;
                    case '9':
                            num1[0][1] = '-';
                            num1[1][0] = '|';
                            num1[1][2] = '|';
                            num1[2][0] = '|';
                            num1[2][2] = '|';
                            num1[3][1] = '-';
                            num1[1][1] = '_';
                            for(i = 0; i < MAX_STAT_ROW; i++)  
                            {       for(k = 0; k < MAX_STAT_COL; k++)
                             {printf("%c", num1[i][k]);}
                            }
                            break;
    
            }
    }
    Last edited by youareafever; 12-07-2008 at 08:02 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  3. Generating Dates! Compiles but does not work...
    By ottomated in forum C Programming
    Replies: 11
    Last Post: 04-22-2008, 03:58 AM
  4. program wont work, why?
    By chasingxsuns in forum C Programming
    Replies: 11
    Last Post: 02-02-2006, 04:38 PM