Thread: I need help with this programming question!

  1. #1
    Registered User
    Join Date
    Feb 2014
    Posts
    5

    Post I need help with this programming question!

    I think i have the basics down for this program but I still am not sure what to do after. I have attached my assignment and my code so far.
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    That's a unique assignment. Long to read, but actually really simple.

    What are you having problems with? Posting a requirements spec. and some source code doesn't let anyone help you.

  3. #3
    Registered User
    Join Date
    Feb 2014
    Posts
    5
    Well the problem i am having is being able to make it so that it outputs it in that way. I know how to get the first output for time 0, but I have no idea how to get the other times to work. I tried using while and nested for loops but I just don't get how to do it.

    please help me :'(. I been stuck on this for 4 hours.
    Last edited by David Park; 07-28-2014 at 07:05 PM.

  4. #4
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Looked at the code more, found a few things :

    1) Arrays in C are 0-based. In your code you are indexing from 1 to SIZE, when you need to index from 0 to SIZE-1.

    2) You may need to rethink your control loop for outputting the configurations.

    I suggest having an array of 15 boolean flags (T = alarm sounding, F = not sounding). The values of 45 and 120 are arbitrary.

    at time 0, the configuration is equal to the one entered by the user.

    then make a loop that continually updates your array until every value is T.

    Or you could use this:
    Code:
    enum AlarmStatus { ON = 45, OFF = 120 };
    
    enum AlarmStatus STATIONS[NUM_STATIONS];
    
    scanf("%d", &STATIONS[i]);
    
    if (STATIONS[i] == ON)
        // ...
    That way, you can input as integers but use more meaningful names inside program.
    Last edited by MacNilly; 07-28-2014 at 07:19 PM.

  5. #5
    Registered User
    Join Date
    Feb 2014
    Posts
    5
    Could you give an example as to how to do that in code format? I am in an introductory CS class, so I am not the most experienced programmer.

  6. #6
    Registered User
    Join Date
    Feb 2014
    Posts
    5
    I can't use enum in my assignment because the class restricts to the materials we learned so far. Could you show the boolean method in code? I hope I am not asking for too much, it's greatly appreciated.

  7. #7
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    I can't and wouldn't post a complete source code.

    Homework policy.

    Since you can't use enums, you might as well just use a define like so

    Code:
    #define ALARM_ON 120
    #define ALARM_OFF 45

  8. #8
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Ok, I'll just post an outline of a simple algorithm.

    Code:
    int done = 0;
    while (!done) {
      // display current station conf.
      displayStations();
      // update station conf.
      updateStations();
      if (all stations alarms sounding)
        done = 1;
    }
    I think that is about as far as I can go!

  9. #9
    Registered User
    Join Date
    Feb 2014
    Posts
    5
    Thank you! It helps!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Total newb to programming here... Question about the many programming languages. Ty!
    By tsubotakid1 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 10-05-2003, 10:32 AM
  2. C Programming Question
    By TK in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 07-04-2002, 07:11 PM
  3. UIL Programming Question
    By araknid in forum C++ Programming
    Replies: 7
    Last Post: 02-11-2002, 08:11 PM
  4. Programming question
    By face_master in forum C++ Programming
    Replies: 1
    Last Post: 08-26-2001, 07:00 AM

Tags for this Thread