programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# Function - Can someone let me know if I did this right?

Greenhorn
Posts: 18
• Number of slices to send:
Optional 'thank-you' note:
This is my assignment:
Exercise 15: Write a script to generate a random number for the variable m, the value generated for m should range from 1 to 100. Now define a function f with one parameter n that displays either the message n is an odd number or the message n is an even number. Call this function twice for two random numbers. That is your script should generate a random number for m and call f(m). Then it should generate a second random number for m and call f(m) again. For example, if the random number generator generates 26 for m as the first number and then calls f(m). Then the output for the first line should look like:

26 is an even number.

Then the function is called again so the random number generator generates second number, 35 for m, and then it calls f(m). The output for the second line should look like:

Now, this is the code I did, I know it's not right, but I'm stuck..

I'd really appreciate some help.. Thanks, Mimi.

Sheriff
Posts: 67747
173
• Number of slices to send:
Optional 'thank-you' note:
Look at your code and look at the assignment. Where does your code deviate from the instructions?

Also, look into the modulus operator for an easier way to determine odd vs. even.

 With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.