Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Smart Cow
Old
bassj8489
Guest
 
Status:
Posts: n/a
Default Smart Cow - 04-05-2011, 03:44 PM

I have to do an assignment that makes a cow pick the highest number out of a user designated sequence of numbers: The cow asks how many numbers are in the sequence, the user enters a number; then the cow asks for the numbers. He is supposed to tell you which one is the highest. I am supposed to use three variables: numberOfItems, highestNumber, and currentNumber; also a for loop with an embedded if statement...I can get the cow to go through the script and ask for the sequence and the numbers but not to tell which number is the highest.....help please??
   
Reply With Quote
Old
reuben2011
Senior Member
 
reuben2011's Avatar
 
Status: Offline
Posts: 489
Join Date: Sep 2009
Location: Hawaii
Default 04-05-2011, 06:46 PM

Quote:
Originally Posted by bassj8489 View Post
I have to do an assignment that makes a cow pick the highest number out of a user designated sequence of numbers: The cow asks how many numbers are in the sequence, the user enters a number; then the cow asks for the numbers. He is supposed to tell you which one is the highest. I am supposed to use three variables: numberOfItems, highestNumber, and currentNumber; also a for loop with an embedded if statement...I can get the cow to go through the script and ask for the sequence and the numbers but not to tell which number is the highest.....help please??
Ok, I'm going to assume you have a statement like:
Code:
currentNumber set value to ask user for number
Right after that put:
Code:
if(currentNumber > highestNumber)
{
highestNumber set value to currentNumber
}
Then you display the value of highestNumber to display the highest number. Hope this helps!


Projects
-Escape the Kitchen
-That ninja animation
-Hill Collision

Upcoming Projects
-Some penguin adventure game?
   
Reply With Quote
Old
bassj8489
Guest
 
Status:
Posts: n/a
Default 04-05-2011, 07:10 PM

I'm glad you posted that because that is what I worked out since I posted and it works, but I'm still a little fuzzy on how to establish the highest number...thank you for replying, I wasn't sure anybody was going to get to me in time; this and another assignment are due tonight before midnight
   
Reply With Quote
cow
Old
bassj8489
Guest
 
Status:
Posts: n/a
Default cow - 04-05-2011, 07:28 PM

so far I have:
numberOfItems.set(value, NumberDialog( question=Enter a Number);
for (int index=0;index<numberOfItems;index++{currentNumber. set(value, NumberDialog(question=Enter a Number);
}
if(currentNumber>highestNumber) {highestNumber.set(value, currentNumber);
cow.say(The highest number is + highestNumber.toString);
}
esle

}
   
Reply With Quote
Old
reuben2011
Senior Member
 
reuben2011's Avatar
 
Status: Offline
Posts: 489
Join Date: Sep 2009
Location: Hawaii
Default 04-05-2011, 08:00 PM

Hmm... try:

Code:
numberOfItems.set(value, NumberDialog(question=Enter a Number);
for (int index=0;index<numberOfItems;index++)
{
currentNumber. set(value, NumberDialog(question=Enter a Number);
if(currentNumber>highestNumber) {
highestNumber.set(value, currentNumber);
}
else
{
do nothing
}
} cow.say(The highest number is + highestNumber.toString);


Projects
-Escape the Kitchen
-That ninja animation
-Hill Collision

Upcoming Projects
-Some penguin adventure game?
   
Reply With Quote
cow
Old
bassj8489
Guest
 
Status:
Posts: n/a
Default cow - 04-05-2011, 08:26 PM

No dice sir....there has to be another way to have the highestNumber variable assign itself the correct number....
   
Reply With Quote
cow
Old
bassj8489
Guest
 
Status:
Posts: n/a
Default cow - 04-05-2011, 08:30 PM

I made a mistake when entering the code, your suggestion did work...thanks a lot!!!! I had exactly the same thing except for those last two variables being defined incorrectly...its the small things everytime. Thanks again, I may be back, I still have one more assignment.
   
Reply With Quote
Old
reuben2011
Senior Member
 
reuben2011's Avatar
 
Status: Offline
Posts: 489
Join Date: Sep 2009
Location: Hawaii
Default 04-06-2011, 12:48 PM

Ok, no prob! Feel free to hit us up with any questions!


Projects
-Escape the Kitchen
-That ninja animation
-Hill Collision

Upcoming Projects
-Some penguin adventure game?
   
Reply With Quote
Reply

Thread Tools
Display Modes

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

Forum Jump



Copyright ©2017, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.