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.