• Post Reply Bookmark Topic Watch Topic
  • New Topic
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

Parameter of an array help

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Struggling with this program that I'm working on for practice on my upcoming final. Not a CS person by any means kind of just took the course to get my feet wet but this one has me struggling the prompt is basically:

>"Design and implement an application that reads an integer value representing a year from the user. The purpose of the program is to determine if the year is a leap year in the Gregorian calendar. A year is a leap year if it is divisible by 4, unless it is also divisible by 100 but not 400. Produce an error message for any input value less than 1582 (the year the Gregorian calendar was adopted).

(I did this but then there's a question afterwards where you modify your answer) :

>"Modify the solution to the program above so that the user can evaluate multiple years. Allow the user to terminate the program using an appropriate sentinel value. Validate each input value to ensure it is greater or equal to 1582."

Here's what I have:




The struggle I'm having is around the for loop where I want the program to check to see if the user's input falls within the range (>= 1582) but I'm struggling with how to get that in there and it's starting to bug me.

Would really appreciate some help, like I said I'm no expert so what I'm doing is probably very obvious to you and I'll feel dumb but I had nowhere else to turn.
 
Ranch Hand
Posts: 75
Android Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right now, you're using the loop variable and not the values contained in your array.

You need to access the values of the array.


It also looks like you're not checking if it is >= 1582.
Note: I haven't really looked over the logic, so I'm not sure if it's doing what its supposed to.
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure you need to store the values in an array ? The question doesn't say anything about keeping the values. You are also asking the user how many values are going to be entered. The question actually says you should use a sentinel value to allow the user to indicate when they are finished.
My reading of the question suggests you need something like (in pseudo code)
 
Whose rules are you playing by? This tiny ad doesn't respect those rules:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic