Jump to content

URGENT assistance in C Programming

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1
jclarke

jclarke

    Programmer

  • Members
  • PipPipPipPip
  • 106 posts
Hello again - I know I have returned once again, been busy with uni stuff lately.

Now, just need some assistance on this one which I am not sure how to put it this way in C programming under linux - anyone help?

Quote

You have a clock with 4 buttons, H+, H-, M+, M-. The two H buttons change hours without affecting the minutes, while the two M buttons change the minutes without affecting the hours.

H+ increases hours by 1. If hours was 23, pressing H+ sets hours to 00.
H- decreases hours by 1. If hours was 00, pressing H- sets hours to 23.
M+ increases minutes by 1. If minutes was 59, pressing M+ sets minutes to 00.
M- decreases minutes by 1, If minutes was 00, pressing M- sets minutes to 59.

Write a C prgram which will read two times and determine the smallest number of button presses to change the setting from the first time to second time.

There will be two lines of input, each containing a time, the hours followed by the minutes.

The output will be a single number.

Example:

Input: 1755

Output: 2

Limit: The hours will be in the range [0...23] and the minutes in the range [0...59]


#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
We don't write your homework for you, but we'll gladly help you. Why don't you write down the steps you would take to do it manually, and then work from there? Post what you've got once you're done with the manual part so I can point you in the right direction.
sudo rm -rf /

#3
jclarke

jclarke

    Programmer

  • Members
  • PipPipPipPip
  • 106 posts
Thats OK, I will get the code attempt tomorrow night, and see what happens from there..

it is pretty late down here right now (Im in Australia)

#4
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
While( !User.hasAnswer )
{
     User.askQuestion();

     if( User.postCode && User.putForthEffort )
     {
          CodeCallMembers.Help();
          User.hasAnswer = true;
     }
     else
     {
          CodeCallMembers.Laugh();
     }
}

-CDG10620
Software Developer

#5
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
Just because I'm an insufferable ****, I would amend your if clause to:
if( User.question.type ==  Question::Homework )
{
    <original if clause here>
}
else if( User.question.type == Question::ExpandKnowledge )
    CodeCallMembers.Help();
else
    CodeCallModerator.delete(User.question);

sudo rm -rf /

#6
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
That's a good point. I won't argue with that. I just felt that the Question::Fun would not apply to someone who is obviously lazy and wants us to do homework for them. Typically they post the question, WingedPanther or someone else says "Wow this looks like homework" and then the person admits is a homework assignment or a project. :)
-CDG10620
Software Developer

#7
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts

cdg10620 said:

I just felt that the Question::Fun would not apply to someone who is obviously lazy and wants us to do homework for them.
Hence the else if clause. Or am I completely missing something here?
sudo rm -rf /

#8
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
I understand what you're saying. Maybe we'll have to add that in. :)


While( !User.hasAnswer )
{
   User.askQuestion();
     
   if( User.question.type ==  Question::Homework )
   {
      if( User.postCode && User.putForthEffort )
      {
         CodeCallMembers.Help();
         User.hasAnswer = true;
      }
      else
      {
         CodeCallMembers.Laugh();
      }
   }
   else if( User.question.type == Question::ExpandKnowledge )
      CodeCallMembers.Help();
   else
      CodeCallModerator.delete(User.question);    
}


Edited by cdg10620, 25 March 2010 - 10:50 AM.
Fixed crappy formatting. :)

-CDG10620
Software Developer

#9
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
Oooh, terrible formatting. :)
sudo rm -rf /

#10
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
better?
-CDG10620
Software Developer

#11
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
Yes, thank you. :D
sudo rm -rf /

#12
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
Glad I could make you happy. :P
-CDG10620
Software Developer