Question
IPC144 workshop5 part2 I have been an error but when I find out this in output, how can I fix it??? please help me! Checking
IPC144 workshop5 part2
I have been an error but when I find out this in output, how can I fix it??? please help me!
Checking output: In line number 73 of your output: The output should be: -------------------- ^ But your output is: -------------------- ^
Unmatched character details: The character in column 3 is supposed to be: [-] ASCII code(45) but you printed [Space] ASCII code(32)
Outputs don't match. Submission aborted!
To see exactly what is wrong, open the following two files in this directory and compare them: Your output file: output.txt Correct output file: w5p2Output.txt
/* ================================================== Workshop #5 (Part-2): ================================================== Name : Deuknam Kim ID : 133737205 Email : g..4@myseneca.ca Section: ZAA */ #define _CRT_SECURE_NO_WARNINGS
#include
#define MAX_PATH_LENGTH 70 #define MIN_PATH_LENGTH 10 #define GAME_MULTIPLIER 5
struct PlayerInfo { int playerLives; int treasureCount; char playerSym; int currentMove;
}; struct GameInfo { int gameLength; int gameMoves; int bombInput[MAX_PATH_LENGTH]; int treasureInput[MAX_PATH_LENGTH]; char revealedPosition[MAX_PATH_LENGTH];
};
int main(void) { struct PlayerInfo playerData = { 0 }; struct GameInfo gameSettings = { 0 };
const double setPercentage = 0.75; int maxMoves; int a, b; char hiddenPosition = '-';
printf("================================ "); printf(" Treasure Hunt! "); printf("================================ "); printf("PLAYER Configuration "); printf("-------------------- "); printf("Enter a single character to represent the player: "); scanf(" %c", &playerData.playerSym);
a = 0; do { printf("Set the number of lives: "); scanf("%d", &playerData.playerLives);
if (playerData.playerLives >= 1 && playerData.playerLives <= 10) { printf("Player configuration set-up is complete "); a++; } else { printf(" Must be between 1 and 10! "); } } while (a < 1);
printf("GAME Configuration "); printf("------------------ "); a = 0; do { printf("Set the path length (a multiple of 5 between %d-%d): ", MIN_PATH_LENGTH, MAX_PATH_LENGTH); scanf("%d", &gameSettings.gameLength); if (gameSettings.gameLength >= MIN_PATH_LENGTH && gameSettings.gameLength <= MAX_PATH_LENGTH && ((gameSettings.gameLength % GAME_MULTIPLIER) == 0)) { a++; } else { printf(" Must be a multiple of 5 and between %d-%d!!! ", MIN_PATH_LENGTH, MAX_PATH_LENGTH); } } while (a < 1);
a = 0; do { printf("Set the limit for number of moves allowed: "); scanf("%d", &gameSettings.gameMoves); maxMoves = (gameSettings.gameLength * setPercentage); if (gameSettings.gameMoves < playerData.playerLives || gameSettings.gameMoves > maxMoves) { printf(" Value must be between %d and %d ", playerData.playerLives, maxMoves); } else { printf(" "); a++; } } while (a < 1);
printf("BOMB Placement "); printf("-------------- "); printf("Enter the bomb positions in sets of 5 where a value "); printf("of 1=BOMB, and 0=NO BOMB. Space-delimit your input. "); printf("(Example: 1 0 0 1 1) NOTE: there are %d to set! ", gameSettings.gameLength); for (a = 0; a < (gameSettings.gameLength); a = a + 5) { printf(" Positions [%2d-%2d]: ", a + 1, a + 5); scanf("%d %d %d %d %d", &gameSettings.bombInput[a], &gameSettings.bombInput[a + 1], &gameSettings.bombInput[a + 2], &gameSettings.bombInput[a + 3], &gameSettings.bombInput[a + 4]);
} printf("BOMB placement set ");
printf("TREASURE Placement "); printf("------------------ "); printf("Enter the treasure placements in sets of 5 where a value "); printf("of 1=TREASURE, and 0=NO TREASURE. Space-delimit your input. "); printf("(Example: 1 0 0 1 1) NOTE: there are %d to set! ", gameSettings.gameLength); for (a = 0; a < (gameSettings.gameLength); a = a + 5) { printf(" Positions [%2d-%2d]: ", a + 1, a + 5); scanf("%d %d %d %d %d", &gameSettings.treasureInput[a], &gameSettings.treasureInput[a + 1], &gameSettings.treasureInput[a + 2], &gameSettings.treasureInput[a + 3], &gameSettings.treasureInput[a + 4]); } printf("TREASURE placement set ");
printf("GAME configuration set-up is complete... ");
printf("------------------------------------ "); printf("TREASURE HUNT Configuration Settings "); printf("------------------------------------ "); printf("Player: "); printf(" Symbol : %c ", playerData.playerSym); printf(" Lives : %d ", playerData.playerLives); printf(" Treasure : [ready for gameplay] "); printf(" History : [ready for gameplay] ");
printf("Game: "); printf(" Path Length: %d ", gameSettings.gameLength); printf(" Bombs : "); for (a = 0; a < (gameSettings.gameLength); a++) { printf("%d", gameSettings.bombInput[a]); } printf(" "); printf(" Treasure : "); for (a = 0; a < (gameSettings.gameLength); a++) { printf("%d", gameSettings.treasureInput[a]); }
printf(" "); printf("==================================== "); printf("~ Get ready to play TREASURE HUNT! ~ "); printf("==================================== ");
do { printf(" "); for (a = 1; a < (playerData.currentMove + 1); a++) { if (a != playerData.currentMove) { printf(" "); } else if (playerData.currentMove == 0) { printf(" "); } else { printf("%c ", playerData.playerSym); } } //--------------------------------------------------------------------------------------------------- // LINE 2
if (gameSettings.bombInput[playerData.currentMove] == 1 && gameSettings.treasureInput[playerData.currentMove] == 0) //bomb { gameSettings.revealedPosition[playerData.currentMove] = '!'; } else if (gameSettings.treasureInput[playerData.currentMove] == 1 && gameSettings.bombInput[playerData.currentMove] == 0) //treasure { gameSettings.revealedPosition[playerData.currentMove] = '$'; } else if (gameSettings.bombInput[playerData.currentMove] == 1 && gameSettings.treasureInput[playerData.currentMove] == 1) // bomb and treasure { gameSettings.revealedPosition[playerData.currentMove] = '&'; } else if (gameSettings.bombInput[playerData.currentMove] == 0 && gameSettings.treasureInput[playerData.currentMove] == 0) //nothing { gameSettings.revealedPosition[playerData.currentMove] = '.'; }
if (playerData.currentMove == 0) { for (a = 0; a < (gameSettings.gameLength); a++) { printf("%c", hiddenPosition); gameSettings.revealedPosition[a] = hiddenPosition; } } else { printf(" "); for (a = 0; a < (gameSettings.gameLength); a++) { printf("%c", gameSettings.revealedPosition[a]); } } //---------------------------------------------------------------------------------------------------
printf(" "); for (a = 1, b = 1; a <= gameSettings.gameLength; a++) { if (a % 10 == 0) { printf("%d", b); b++; } else { printf("|"); } } printf(" "); for (a = 1, b = 1; a <= gameSettings.gameLength; a++) { if (a % 10 == 0) { printf("0"); b = 1; } else { printf("%d", b); b++; } }
printf(" "); printf("+---------------------------------------------------+ "); printf(" Lives: %2d | Treasures: %2d | Moves Remaining: %2d ", playerData.playerLives, playerData.treasureCount, gameSettings.gameMoves); printf("+---------------------------------------------------+ ");
do { a = 0; printf("Next Move [1-%d]: ", gameSettings.gameLength); scanf("%d", &playerData.currentMove); if (playerData.currentMove >= 1 && playerData.currentMove <= gameSettings.gameLength) { printf(" "); a++; } else { printf(" Out of Range!!! "); } } while (a < 1);
if (gameSettings.revealedPosition[playerData.currentMove] == hiddenPosition) { if (gameSettings.bombInput[playerData.currentMove] == 0 && gameSettings.treasureInput[playerData.currentMove] == 0) { printf("===============> [.] ...Nothing found here... [.] "); gameSettings.gameMoves -= 1; } else if (gameSettings.bombInput[playerData.currentMove] == 1 && gameSettings.treasureInput[playerData.currentMove] == 0) { printf("===============> [!] !!! BOOOOOM !!! [!] "); playerData.playerLives -= 1; gameSettings.gameMoves -= 1; } else if (gameSettings.treasureInput[playerData.currentMove] == 1 && gameSettings.bombInput[playerData.currentMove] == 0) { printf("===============> [$] $$$ Found Treasure! $$$ [$] "); playerData.treasureCount += 1; gameSettings.gameMoves -= 1; } else if (gameSettings.bombInput[playerData.currentMove] == 1 && gameSettings.treasureInput[playerData.currentMove] == 1) { printf("===============> [&] !!! BOOOOOM !!! [&] "); printf("===============> [&] $$$ Life Insurance Payout!!! [&] "); gameSettings.gameMoves -= 1; playerData.treasureCount += 1; playerData.playerLives -= 1; } } else { printf("===============> Dope! You've been here before! "); } } while (playerData.playerLives != 0 && gameSettings.gameMoves != 0);
//-------------------------------------------------------------------------
printf("No more LIVES remaining! ");
printf(" "); for (a = 1; a < (playerData.currentMove + 1); a++) { if (a != playerData.currentMove) { printf(" "); } else if (playerData.currentMove == 0) { printf(" "); } else { printf("%c ", playerData.playerSym); } }
if (gameSettings.bombInput[playerData.currentMove] == 1 && gameSettings.treasureInput[playerData.currentMove] == 0) //bomb { gameSettings.revealedPosition[playerData.currentMove] = '!'; } else if (gameSettings.treasureInput[playerData.currentMove] == 1 && gameSettings.bombInput[playerData.currentMove] == 0) //treasure { gameSettings.revealedPosition[playerData.currentMove] = '$'; } else if (gameSettings.bombInput[playerData.currentMove] == 1 && gameSettings.treasureInput[playerData.currentMove] == 1) // bomb and treasure { gameSettings.revealedPosition[playerData.currentMove] = '&'; } else if (gameSettings.bombInput[playerData.currentMove] == 0 && gameSettings.treasureInput[playerData.currentMove] == 0) //nothing { gameSettings.revealedPosition[playerData.currentMove] = '.'; }
if (playerData.currentMove == 0) { for (a = 1; a < (gameSettings.gameLength + 1); a++) { printf("%c", hiddenPosition); gameSettings.revealedPosition[a] = hiddenPosition; } } else { printf(" "); for (a = 1; a < (gameSettings.gameLength + 1); a++) { printf("%c", gameSettings.revealedPosition[a]); } } printf(" "); for (a = 1, b = 1; a <= gameSettings.gameLength; a++) { if (a % 10 == 0) { printf("%d", b); b++; } else { printf("|"); } } printf(" "); for (a = 1, b = 1; a <= gameSettings.gameLength; a++) { if (a % 10 == 0) { printf("0"); b = 1; } else { printf("%d", b); b++; } }
printf(" "); printf("+---------------------------------------------------+ "); printf(" Lives: %2d | Treasures: %2d | Moves Remaining: %2d ", playerData.playerLives, playerData.treasureCount, gameSettings.gameMoves); printf("+---------------------------------------------------+ ");
printf("################## "); printf("# Game over! # "); printf("################## "); printf("You should play again and try to beat your score!! ");
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started