Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Switch Statement using dbInput to enter a letter

Author
Message
LeonardInO 49
13
Years of Service
User Offline
Joined: 26th Feb 2011
Location:
Posted: 7th Mar 2011 05:38
I am doing an exercise for a call where I am using a switch statement. There are two choices r or f. I can not get the dbIput function to accept either letter. Here is the code[#include "DarkGDK.h"

//declare and initialize variables

void DarkGDK()
{
int dayNumber = 0; //tracks number of days elapsed
int menCount = 8; //tracks the number of men left
int foodCount = 80;//tracks the food left
char inputValue;

const int FOOD_LOST = 10; //Number of men lost each time player chooses to run
const int MEN_LOST = 1; //Number of men lost each time player chooses to fight, or if there's a food shortage
const int TRIP_DURATION = 10; // TOTAL TRIP DURATION

bool isOutOfFood; // used to check for food shortage
bool isOutOfMen; // used to check to see if everyone dies.
bool areWeThereYet; //used to check to see if player has reached destination.
//Display introduction
dbPrint("********************************************************");
dbPrint("This is a story of your journey to California from Fort Laramie. Your journey is to take ten days.");
dbPrint("********************************************************");
dbPrint("");
dbPrint( "Your journey begins: ");

//go to next day
dayNumber++;
//display daily summary
dbPrint("-----------------------------------------------------------");
dbPrint("Day "); dbPrint(dbStr(dayNumber)); dbPrint("Your "); dbPrint(dbStr(menCount));
dbPrint(" men consumed ");
dbPrint(dbStr(menCount));
dbPrint(" portions of food.");
foodCount = (foodCount - menCount);
dbPrint("You have"); dbPrint(dbStr(menCount)); dbPrint(" men and "); dbPrint(dbStr(foodCount)); dbPrint(" portions of food left.");
dbPrint("-----------------------------------------------------------");

//display conflict

dbPrint("You are ambushed by bandits do you (f)ight or (r)un?");
inputValue = dbInput();

switch(inputValue)
{
case 'f':
{
//display fight summary
dbPrint("You stood your ground and chased off the bandits.");

dbPrint("Unfortunatly "); dbPrint(dbStr(MEN_LOST)); dbPrint(" of your men was killed in the fight.");
menCount-=MEN_LOST;

//Display daily ending summary
dbPrint("You have "); dbPrint(dbStr(menCount)); dbPrint(" men and "); dbPrint(dbStr(foodCount)); dbPrint(" portions of food left.");

//go to next day
dayNumber++;
//display daily summary
dbPrint("-----------------------------------------------------------");
dbPrint("Day ");
dbPrint(dbStr(dayNumber));
dbPrint("Your "); dbPrint(dbStr(menCount));
dbPrint(" men consumed ");
dbPrint(dbStr(menCount));
dbPrint(" portions of food.");
foodCount = (foodCount - menCount);
dbPrint("You have"); dbPrint(dbStr(menCount)); dbPrint(" men and "); dbPrint(dbStr(foodCount)); dbPrint(" portions of food left.");
dbPrint("-----------------------------------------------------------");


break;
}
case 'r':

{
dbPrint("You ran away and lost one wagon containing ");dbPrint(dbStr(FOOD_LOST)); dbPrint( " food portions.");
//deduct food count
foodCount -= FOOD_LOST;

//Display daily ending summary
dbPrint("You have "); dbPrint(dbStr(menCount)); dbPrint(" men and "); dbPrint(dbStr(foodCount)); dbPrint(" portions of food left.");

//go to next day
dayNumber++;
//display daily summary
dbPrint("-----------------------------------------------------------");
dbPrint("Day ");
dbPrint(dbStr(dayNumber));
dbPrint("Your "); dbPrint(dbStr(menCount)); dbPrint(" men consumed "); dbPrint(dbStr(menCount)); dbPrint(" portions of food.");
foodCount = foodCount - menCount;
dbPrint("You have "); dbPrint(dbStr(menCount)); dbPrint(" men and "); dbPrint(dbStr(foodCount)); dbPrint(" portions of food left.");
dbPrint("-----------------------------------------------------------");

break;
}
default:
{
dbPrint("You made an illegal choice.");
break;
}
}]
Wikaman1
16
Years of Service
User Offline
Joined: 17th Aug 2008
Location: Scotland
Posted: 7th Mar 2011 20:59
try using this instead:



to find the other scan codes, look here -

http://farm3.static.flickr.com/2641/3992820795_32f1e0b541_o.gif

Login to post a reply

Server time is: 2024-11-19 12:32:24
Your offset time is: 2024-11-19 12:32:24