Need Help With A Assignment that must be done in C. - Purpose of program is to m
ID: 3681238 • Letter: N
Question
Need Help With A Assignment that must be done in C.
- Purpose of program is to make a game (Jeopardy)
- Program must read a text file that reads the following format (seperated by tab): Question, Answer, Category and Points ( I was going to use getLine() to read each input seperated by tab)
- Class definition instance variables populated by the file
- Multi-dimensional array 5x5 - each element of the array should hold an object
- Exception handling to ensure that user enters correct element to chose the question from, to make sure that the user enters 'What is ?' or 'Who is ?'.
- The program should mark the user incorrect if not answered in a question format
- Exception handling for file I/O and user input for when the user selects the board element to play.
-Keep track of the total points earned for each category and total points earned for each game.
- Display the game board at each round for the user to see what is was correct and what was incorrect and for user to pick category and score to chose from.
- Display a score table at the end showing each category, which ones were correct, which ones were incorrect, the total score per category and the total score for the game.
Explanation / Answer
Answer:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
const int MAX_TOTAL = 100;
const int MIN_TOTAL = 25;
int keepInt( const char* text, const int min, const int max );
int keepChr( const char* text );
int expand();
void displayDice( const int side );
void startGame();
int main()
{
do
{
startGame();
}
while( expand() );
return 0;
}
void startGame()
{
int completegamescoreTotal = 0, firstPlayer = 0, secondPlayer = 0;
int playerCount = 1;
srand( time(0) );
printf( "Welcome to THE GAME OF JEOPARDY. " );
completegamescoreTotal = keepInt( "What will you like to be the end-game total ", MIN_TOTAL, MAX_TOTAL );
while( firstPlayer < completegamescoreTotal && secondPlayer < completegamescoreTotal )
{
int check;
if( playerCount == 1 )
{
printf( " It is first player's turn Do you want to roll or hold?? " );
do
{
check = keepChr( "(r/h) ? " );
}
while( !( check == 'r' || check == 'h') );
if( check == 'r' )
{
const int occupy = rand() % 6 +1;
displayDice( occupy );
if( occupy == 1 )
playerCount = 2;
else
firstPlayer += occupy;
}
else
{
printf( "Ok !!!!! hold it is now " );
playerCount = 2;
}
}
else
{
const int occupy = rand() % 6 +1;
printf( " It is second player's turn" );
keepChr( "Hit 'Enter' key when ready to roll " );
displayDice( occupy );
if( occupy == 1 )
playerCount = 1;
else
secondPlayer += occupy;
}
printf( "first player has %d and second player has %d ", firstPlayer, secondPlayer );
}
if( firstPlayer < secondPlayer )
{
if( secondPlayer > completegamescoreTotal )
printf( "Second player past over so player one wins %d! ", firstPlayer );
else
printf( "Second player has high score and wins %d! ", secondPlayer );
return;
}
if( firstPlayer > completegamescoreTotal )
printf( "First player past over so player two wins %d! ", secondPlayer );
else
printf( "First player has high score and wins %d! ", firstPlayer );
}
void displayDice( const int side )
{
printf("+---------+ ");
switch( side )
{
case 1:
printf("| | ");
printf("| 0 | ");
printf("| | ");
break;
case 2:
printf("| 0 | ");
printf("| | ");
printf("| 0 | ");
break;
case 3:
printf("| 0 | ");
printf("| 0 | ");
printf("| 0 | ");
break;
case 4:
printf("| 0 0 | ");
printf("| | ");
printf("| 0 0 | ");
break;
case 5:
printf("| 0 0 | ");
printf("| 0 | ");
printf("| 0 0 | ");
break;
case 6:
printf("| 0 0 0 | ");
printf("| | ");
printf("| 0 0 0 | ");
}
printf("+---------+ ");
}
int keepInt( const char* text, const int min, const int max )
{
int stay = 0;
while( 1 )
{
printf( text );
fflush( stdout );
if( scanf( "%d", &stay ) == 1 && getchar() == ' ' )
{
if( min <= stay && stay <= max )
break;
printf( "stayid range here is %d..%d ... ", min, max);
}
else
{
printf( "Integer input only here please ... " );
while( getchar() != ' ' );
}
}
return stay;
}
int keepChr( const char* text )
{
int chr;
printf( text );
fflush( stdout );
chr = getchar();
if( chr != ' ' )
while( getchar() !=' ' );
return chr;
}
int expand()
{
const int c = keepChr( " expand (y/n) ? " );
if( c == 'n' || c == 'N' )
return 0;
return 1;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.