New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

new to programing


Post Reply New Thread Subscribe

 
Thread Tools
baoh01

 
Member Since: Jul 21, 2010
Posts: 6
baoh01 is on a distinguished road

baoh01 is offline
Hey Guys, I really need some help here. I am new to programming and I reading a book that focused on people like me...."beginners, noobs..." you know. I have been stuck working on an exercise for the last 5 days and I have gotten it to what I would like for it to be but I AM STUCK!!!
The exercise requires me to insert a count of how many times the user guesses before they get the correct answer.
I get the one count, but for some reason I can get it to increment.
I have looked around for the answer but the ones that I have found, touch on subjects that the book has not touched upon.
Please if you can assist, it would be great.

Here is the code as of last night:

int randomNumber = 1;
int userGuess = 1;
int countGuesses = 1;
int moreGuesse = 1;
moreGuesse++;
BOOL oneGuess = TRUE;
BOOL guessing = TRUE;
BOOL continueGuessing = TRUE;
BOOL keepPlaying = TRUE;
char yesNo = ' ';
while (keepPlaying)
{
randomNumber = (random()%101);
NSLog(@"The random Number to guess is: %i", randomNumber);
continueGuessing = TRUE;
while (continueGuessing)
{
NSLog(@"Pick a Number between 0 and 100.");
scanf ("%i", &userGuess);
fgetc(stdin);//remove CR/LF i.e extra character
if (userGuess == randomNumber)
{
continueGuessing = FALSE;
NSLog(@"Correct Number!");
}
//nested if statement
else if (userGuess > randomNumber)//an else if statement
{
//user guessed too high
NSLog(@"Your guess is too high");
}
else
{
//no reason to check if userGuess < randomNumber. It has to be
NSLog(@"Your guess is too low");

}
//refactored from our Alice app. This way we only have to code once.
NSLog(@"The user guessed %d", userGuess);

if (oneGuess != randomNumber)
{
NSLog(@"You have guessed %d time", countGuesses);
}
else if (guessing > randomNumber)
{
NSLog(@"You have guessed %d times", moreGuesse);
}
}
NSLog(@"Play Again? Y or N");
yesNo = fgetc(stdin);
if (yesNo == 'N')
{
keepPlaying = FALSE;
}
}

Any assistance would be very helpfull, if your going to be discouraging and tell me that coding is hard and I should not attempt it...back off I have a keyboard and I am not afraid to use it.....
QUOTE Thanks
baoh01

 
Member Since: Jul 21, 2010
Posts: 6
baoh01 is on a distinguished road

baoh01 is offline
Hey Guys, I really need some help here. I am new to programming and I reading a book that focused on people like me...."beginners, noobs..." you know. I have been stuck working on an exercise for the last 5 days and I have gotten it to what I would like for it to be but I AM STUCK!!!
The exercise requires me to insert a count of how many times the user guesses before they get the correct answer.
I get the one count, but for some reason I can get it to increment.
The count has to increment by one every time that a gues is done incorrectly.
I have looked around for the answer but the ones that I have found, touch on subjects that the book has not touched upon.
Please if you can assist, it would be great.

Here is the code as of last night:

int randomNumber = 1;
int userGuess = 1;
int countGuesses = 1;
int moreGuesse = 1;
moreGuesse++;
BOOL oneGuess = TRUE;
BOOL guessing = TRUE;
BOOL continueGuessing = TRUE;
BOOL keepPlaying = TRUE;
char yesNo = ' ';
while (keepPlaying)
{
randomNumber = (random()%101);
NSLog(@"The random Number to guess is: %i", randomNumber);
continueGuessing = TRUE;
while (continueGuessing)
{
NSLog(@"Pick a Number between 0 and 100.");
scanf ("%i", &userGuess);
fgetc(stdin);//remove CR/LF i.e extra character
if (userGuess == randomNumber)
{
continueGuessing = FALSE;
NSLog(@"Correct Number!");
}
//nested if statement
else if (userGuess > randomNumber)//an else if statement
{
//user guessed too high
NSLog(@"Your guess is too high");
}
else
{
//no reason to check if userGuess < randomNumber. It has to be
NSLog(@"Your guess is too low");

}
//refactored from our Alice app. This way we only have to code once.
NSLog(@"The user guessed %d", userGuess);

if (oneGuess != randomNumber)
{
NSLog(@"You have guessed %d time", countGuesses);
}
else if (guessing > randomNumber)
{
NSLog(@"You have guessed %d times", moreGuesse);
}
}
NSLog(@"Play Again? Y or N");
yesNo = fgetc(stdin);
if (yesNo == 'N')
{
keepPlaying = FALSE;
}
}

Any assistance would be very helpfull, if your going to be discouraging and tell me that coding is hard and I should not attempt it...back off I have a keyboard and I am not afraid to use it.....
QUOTE Thanks

Post Reply New Thread Subscribe


« openmotif version? | Applescript for Mail »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Programing Language Kax OS X - Development and Darwin 4 04-24-2010 02:23 PM
Programing on the Mac hojkoff_101 OS X - Development and Darwin 4 12-16-2008 09:24 PM
Mighty Mouse Button Programing TonyD Switcher Hangout 4 02-04-2008 07:21 PM
A Programing question... Actingrude OS X - Development and Darwin 5 10-01-2007 05:10 PM
Can I put alarm clock on desktop from a script or programing cooljoe815 OS X - Development and Darwin 2 02-05-2007 07:19 PM

All times are GMT -4. The time now is 07:57 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?