Head or Tails game

This is a discussion on Head or Tails game within the C Programming forums, part of the General Programming Boards category; Hello out there: I need some help. This is the Dev-C++ error message: Compiler: Default compiler Building Makefile: "G:\C programming\HW5\Makefile.win" ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    4

    Head or Tails game

    Hello out there:

    I need some help. This is the Dev-C++ error message:

    Compiler: Default compiler
    Building Makefile: "G:\C programming\HW5\Makefile.win"
    Executing make clean
    rm -f get.o main.o play.o prnt.o report_win_loss.o chapt5prob11secondattempt.a


    ANY help will be appreciated!

    I believe I don't have any syntax errors but here is the code in case someone wants to take a look at it: (This is about six files).

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #define MAXWORD 100
    
    char get_call_from_user(void);
    void play(int how_many);
    void prn_final_report(int win, int lose, int how_many);
    void prn_instructions(void);
    void report_a_win(void);
    void report_a_loss(void);
    char toss(void);
    
    #include "heads_or_tails.h"
    
    int main(void)
    {
        char ans;
        int no_of_plays;
        
        printf("\n"
           "THE GAME OF HEADS OR TAILS\n"
           "\n"
           "Do you want instructions?  ");
        scanf(" %c", &ans);
        putchar('\n');
        if (ans == 'y' || ans == 'Y')
           prn_instructions();
        printf("How many times do you want to play?   ");
        scanf("%d", & no_of_plays);
        putchar('\n');
        play( no_of_plays);
        system("pause");
        return 0;
    }      
      
    #include "heads_or_tails.h"
    #include <ctype.h>
    
    char get_call_from_user(void)
    {
        char guess;              /* h = heads,  t = tails */
        
        guess = getchar();
        
        do {
            printf("Call it:  ");
                    
            if (getchar()!= 1 ) {
               printf("\nSORRY: Severe input error - bye!\n\n");
               exit(1);
            }
                  
            if (guess != ('H' || 'h') && guess != ('T' || 't' ) ) {
               printf("\n%s\n\n",
                  "ERROR: Type h for heads, t for tails.");
            }
        } while (guess != ('H' || 'h') && guess != ('T' || 't') ) ;
        if (isupper(guess))
           putchar(tolower(guess));
        return guess;
    }
    
    #include "heads_or_tails.h"
    
    void play(int how_many)    /* machine tosses, user calls */
    {
         int      i, lose = 0, win = 0;
         char     coin;
         
         for (i = 0; i < how_many; ++i) {
             coin = toss();
             if (get_call_from_user() == coin) {
                ++win;
                report_a_win();
             }
             else {
                  ++lose;
                  report_a_loss();
             }
         }
         prn_final_report(win, lose, how_many);
         system("pause");
    }
    
    char toss(void)
    {
        
        int random;
        
        random = (rand() % 2);
        
        if (random == 1)
            return 't';
        if (random == 0)
           return 'h';    
            /* random : 0 = heads,  1 = tails */
    
    
    }
    
    #include "heads_or_tails.h"
    
    void prn_instructions(void)
    {
         printf("%s\n",
            "This is the game of calling heads or tails.\n"
            "I will flip a coin; you call it. If you\n"
            "call it correctly, you win; otherwise,\n"
            "I win.\n"
            "\n"
            "As I toss the (simulated) coin, I will\n"
            "tell you to \"call it.\"  To call heads,\n"
            "type h; to call tails, type t.\n"
            "\n");
    }
    
    void prn_final_report(int win, int lose, int how_many)
    {
         printf("\n%s\n%s%3d\n%s%3d\n%s%3d\n\n",
            "FINAL REPORT:",
            "   Number of games that you won:  ", win,
            "   Number of games that you lost: ", lose,
            "   Total number of games:         ", how_many);
    }
    
    #include "heads_or_tails.h"
    
    void report_a_win(void)
    {
         printf("%s\n", "You win!");
    }
    
    void report_a_loss(void)
    {
         printf("%s\n", "You lose!");
    }

    This is a lot of files; I may have missed one.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    4

    cont'

    *****************
    Last edited by Mercadogs; 10-05-2006 at 11:43 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. Need book to program game into multiplayer...
    By edomingox in forum Game Programming
    Replies: 3
    Last Post: 10-02-2008, 10:26 AM
  3. C# - Building a SCUMM-like game.. questions
    By Iyouboushi in forum Game Programming
    Replies: 0
    Last Post: 05-24-2008, 11:54 PM
  4. So you want to be a game programmer?
    By dxfoo in forum Game Programming
    Replies: 23
    Last Post: 09-26-2006, 09:38 AM
  5. Try my game
    By LuckY in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-15-2004, 12:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21